Skip to content

Commit

Permalink
Actually, only allow 255 unicode character points
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Sep 15, 2023
1 parent 8e29180 commit 78f8370
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ Depending on which part of the API you use, you can only include what you need:
<tr><th>Class</th><th>Dependency</th><th>Description</th></tr>
<tr><td>CapabilitiesApi</td><td><pre>de.westnordost:osmapi-core:2.0</pre></td><td>Getting server capabilities</td></tr>
<tr><td>PermissionsApi</td><td><pre>de.westnordost:osmapi-core:2.0</pre></td><td>Getting user permissions</td></tr>
<tr><td>MapDataApi</td><td><pre>de.westnordost:osmapi-map:2.1</pre></td><td>Getting map data, querying single elements and their relations toward each other and uploading changes in changesets</td></tr>
<tr><td>MapDataHistoryApi</td><td><pre>de.westnordost:osmapi-map:2.1</pre></td><td>Getting the history and specific versions of elements</td></tr>
<tr><td>MapDataApi</td><td><pre>de.westnordost:osmapi-map:2.2</pre></td><td>Getting map data, querying single elements and their relations toward each other and uploading changes in changesets</td></tr>
<tr><td>MapDataHistoryApi</td><td><pre>de.westnordost:osmapi-map:2.2</pre></td><td>Getting the history and specific versions of elements</td></tr>
<tr><td>NotesApi</td><td><pre>de.westnordost:osmapi-notes:2.0</pre></td><td>Getting finding, creating, commenting on and solving notes</td></tr>
<tr><td>GpsTracesApi</td><td><pre>de.westnordost:osmapi-traces:2.0</pre></td><td>Getting, uploading, updating and deleting GPS traces and trackpoints</td></tr>
<tr><td>ChangesetsApi</td><td><pre>de.westnordost:osmapi-changesets:2.1</pre></td><td>Finding changesets, changeset discussion, subscription and data</td></tr>
<tr><td>ChangesetsApi</td><td><pre>de.westnordost:osmapi-changesets:2.2</pre></td><td>Finding changesets, changeset discussion, subscription and data</td></tr>
<tr><td>UserApi</td><td><pre>de.westnordost:osmapi-user:2.0</pre></td><td>Getting user information</td></tr>
<tr><td>UserPreferencesApi</td><td><pre>de.westnordost:osmapi-user:2.0</pre></td><td>Managing user preferences</td></tr>
</table>

To include everything, add [`de.westnordost:osmapi:4.1`](https://mvnrepository.com/artifact/de.westnordost/osmapi/4.0) as a Maven dependency or download the jar from there.
To include everything, add [`de.westnordost:osmapi:4.2`](https://mvnrepository.com/artifact/de.westnordost/osmapi/4.0) as a Maven dependency or download the jar from there.

### Android

On Android, you need to exclude kxml2 from the dependencies since it is already built-in, like so:

```gradle
dependencies {
implementation 'de.westnordost:osmapi:4.0'
implementation 'de.westnordost:osmapi:4.2'
}
configurations {
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ subprojects {

group = "de.westnordost"

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

ext {
all_version = 4.1
all_version = 4.2
core_version = 2.0
changesets_version = 2.1
changesets_version = 2.2
user_version = 2.0
traces_version = 2.0
notes_version = 2.0
map_version = 2.1
map_version = 2.2
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public void putAll(Map<? extends String, ? extends String> map)

private static void checkKeyValueLength(String key, String value)
{
if(key.length() > 256)
if(key.codePoints().count() >= 256)
{
throw new IllegalArgumentException("For key \"" + key + "\": Key length is limited" +
"to less or equal 256 characters.");
" to less than 256 characters.");
}
if(value.length() > 256)
if(value.codePoints().count() >= 256)
{
throw new IllegalArgumentException("For value \"" + value + "\": Value length is " +
"limited to less or equal 256 characters.");
"limited to less than 256 characters.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ public class OsmTagsTest
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy "
+ "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptu"
+ "a. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gube"
+ "rgren, no sead takimata ";
+ "rgren, no sea takimata ";

@Test public void testStringIsExactly257CharactersLong()
@Test public void testStringIsExactly256CharactersLong()
{
assertEquals(257, TOO_LONG.length());
assertEquals(256, TOO_LONG.length());
}

@Test public void initWithKeyOrValueBelow256CharactersIsFine()
{
StringBuilder cools = new StringBuilder();
while (cools.codePoints().count() < 255)
{
cools.append("\uD83D\uDE0E"); // 😎

Map<String, String> tags = new HashMap<>();
tags.put(cools.toString(), cools.toString());
new OsmTags(tags);
}
}

@Test public void initWithTooLongKeyFails()
Expand Down

0 comments on commit 78f8370

Please sign in to comment.