Avoid splitting surrogate pairs when shortening address labels#12511
Open
greymoth-jp wants to merge 1 commit into
Open
Avoid splitting surrogate pairs when shortening address labels#12511greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
Contributor
can |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The address-label shortening loop in
modules/svg/labels.jstrims one character at a time usingsubstringwith a UTF-16.lengthcount:.lengthcounts UTF-16 code units, solength - 1can land in the middle of a surrogate pair. When the label ends in a character outside the BMP, that character is two code units, andsubstringkeeps only the first half. The result is a lone surrogate that renders as�.This is reachable for real address points.
utilDisplayNameresolves the label fromname, thenaddr:housename, then the house number, and bothnameandaddr:housenameare free text. A house or building name ending in an emoji, or in a CJK Extension B ideograph such as 𠮷 (U+20BB7, which appears in Japanese names), hits this case once the label is wide enough to be trimmed.The fix uses
Array.from(...).slice(0, -1)to drop the last code point instead, the same approachutilUnicodeCharsTruncatedalready takes inmodules/util/util.ts. Strings within the BMP, including all BMP CJK, are unchanged.Checked with node:
I did not add a test, since this runs inside the canvas label-rendering loop.
utilUnicodeCharsTruncated, which uses the same technique, is covered intest/spec/util/util.js.