- Timestamp:
- 2025-08-26T11:27:22+02:00 (6 weeks ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java
r17585 r19437 23 23 import org.openstreetmap.josm.io.OsmTransferCanceledException; 24 24 import org.openstreetmap.josm.tools.Logging; 25 import org.openstreetmap.josm.tools.Utils; 25 26 26 27 /** … … 64 65 String key = entry.getKey(); 65 66 String value = entry.getValue(); 66 if ( key.length() >Tagged.MAX_TAG_LENGTH) {67 if (!Utils.checkCodePointCount(value, Tagged.MAX_TAG_LENGTH)) { 67 68 if (osmPrimitive.isDeleted()) { 68 69 // if OsmPrimitive is going to be deleted we automatically shorten the value … … 73 74 ) 74 75 ); 75 osmPrimitive.put(key, value.substring(0, Tagged.MAX_TAG_LENGTH));76 osmPrimitive.put(key, Utils.shortenString(value, Tagged.MAX_TAG_LENGTH)); 76 77 continue; 77 78 } 78 79 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 79 80 tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.", 80 key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, value.length()81 key, Long.toString(osmPrimitive.getId()), Tagged.MAX_TAG_LENGTH, Utils.getCodePointCount(value) 81 82 ), 82 83 tr("Precondition violation"), -
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r19366 r19437 17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 import org.openstreetmap.josm.tools.Utils; 19 20 20 21 /** … … 313 314 CheckParameterUtil.ensureParameterNotNull(keys, "keys"); 314 315 keys.values().stream() 315 .filter(value -> value != null && value.length() >MAX_CHANGESET_TAG_LENGTH)316 .filter(value -> !Utils.checkCodePointCount(value, MAX_CHANGESET_TAG_LENGTH)) 316 317 .findFirst() 317 318 .ifPresent(value -> { … … 340 341 public void put(String key, String value) { 341 342 CheckParameterUtil.ensureParameterNotNull(key, "key"); 342 if ( value != null && value.length() >MAX_CHANGESET_TAG_LENGTH) {343 throw new IllegalArgumentException("Changeset tag value is too long: " +value);343 if (!Utils.checkCodePointCount(value, MAX_CHANGESET_TAG_LENGTH)) { 344 throw new IllegalArgumentException("Changeset tag value is too long: " + value); 344 345 } 346 345 347 this.tags.put(key, value); 346 348 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r19328 r19437 1016 1016 withErrors.put(p, "UUCV"); 1017 1017 } 1018 if ((value.length() > Tagged.MAX_TAG_LENGTH) && !withErrors.contains(p, "LV")) { 1018 final int codePoints = Utils.getCodePointCount(value); 1019 if (codePoints > Tagged.MAX_TAG_LENGTH && !withErrors.contains(p, "LV")) { 1019 1020 errors.add(TestError.builder(this, Severity.ERROR, LONG_VALUE) 1020 .message(tr("Tag value longer than {0} characters ({1} characters)", Tagged.MAX_TAG_LENGTH, value.length()), s, key)1021 .message(tr("Tag value longer than {0} characters ({1} characters)", Tagged.MAX_TAG_LENGTH, codePoints), s, key) 1021 1022 .primitives(p) 1022 1023 .build()); … … 1065 1066 withErrors.put(p, "ICK"); 1066 1067 } 1067 if (key.length() > Tagged.MAX_TAG_LENGTH && !withErrors.contains(p, "LK")) { 1068 final int codePoints = Utils.getCodePointCount(key); 1069 if (codePoints > Tagged.MAX_TAG_LENGTH && !withErrors.contains(p, "LK")) { 1068 1070 errors.add(TestError.builder(this, Severity.ERROR, LONG_KEY) 1069 .message(tr("Tag key longer than {0} characters ({1} characters)", Tagged.MAX_TAG_LENGTH, key.length()), s, key)1071 .message(tr("Tag key longer than {0} characters ({1} characters)", Tagged.MAX_TAG_LENGTH, codePoints), s, key) 1070 1072 .primitives(p) 1071 1073 .build()); -
trunk/src/org/openstreetmap/josm/tools/TextTagParser.java
r19112 r19437 155 155 if (r == 2 || r == 3) return false; if (r == 4) return true; 156 156 } 157 if ( value.length() >MAX_VALUE_LENGTH) {158 r = callback.warning(tr("Value is too long (max {0} characters):", MAX_VALUE_LENGTH), value, " tags.paste.valuetoolong");157 if (!Utils.checkCodePointCount(value, MAX_VALUE_LENGTH)) { 158 r = callback.warning(tr("Value is too long (max {0} characters):", MAX_VALUE_LENGTH), value, ""); 159 159 if (r == 2 || r == 3) return false; if (r == 4) return true; 160 160 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r19378 r19437 2026 2026 } 2027 2027 } 2028 2029 /** 2030 * Calculate the number of unicode code points. See #24446 2031 * @param s the string 2032 * @return 0 if s is null or empty, else the number of code points 2033 * @since 19437 2034 */ 2035 public static int getCodePointCount(String s) { 2036 if (s == null) 2037 return 0; 2038 return s.codePointCount(0, s.length()); 2039 } 2040 2041 /** 2042 * Check if a given string has more than the allowed number of code points. 2043 * See #24446. The OSM server checks this number, not the value returned by String.length() 2044 * @param s the string 2045 * @param maxLen the maximum number of code points 2046 * @return true if s is null or within the given limit, false else 2047 * @since 19437 2048 */ 2049 public static boolean checkCodePointCount(String s, int maxLen) { 2050 return getCodePointCount(s) <= maxLen; 2051 } 2028 2052 }
Note:
See TracChangeset
for help on using the changeset viewer.