Ignore:
Timestamp:
2025-08-26T11:27:22+02:00 (7 months ago)
Author:
GerdP
Message:

fix #24446: Error loading way-history
Turned out that the OSM server counts the number of unicode code points, not the number of characters when checking the maximum lengths of keys and tags in tags.

  • implement new methods in Util to calculate the number of code points or check agains a given limit
  • fix long standing bug in ApiPreconditionCheckerHook.java which was introduced with r2906 (key -> value)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r19378 r19437  
    20262026        }
    20272027    }
     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    }
    20282052}
Note: See TracChangeset for help on using the changeset viewer.