Fixes an issue where tab titles were not truncating when characters used 4 bytes for encoding (#2254)

* Fixes an issue where tab titles were not truncating when characters used 4 bytes for encoding.

* Changed substringUtf method to be more accurate and added comments
This commit is contained in:
vchske
2025-11-24 12:36:03 -08:00
committed by GitHub
parent 0fac59967a
commit 490309b403
3 changed files with 75 additions and 2 deletions

View File

@@ -26,5 +26,22 @@ describe("StringUtils", () => {
const transformedString: string | undefined = StringUtils.stripSpacesFromString("");
expect(transformedString).toBe("");
});
it("should return the right number of characters regardless of bytes used per character", () => {
// Tried to use a sample of characters across the range for each of the individual byte lengths
const ascii = "!,n~!,n~!,n~";
const twoByteCharacters = "Āā߿܀Āā߿܀Āā߿܀";
const threeByteCharacters = "ࠀ倀ꀀࠀ倀ꀀࠀ倀ꀀ";
const fourByteCharacters = "𐀀𐔀𐨀𐿶𐀀𐔀𐨀𐿶𐀀𐔀𐨀𐿶";
// Used a random character generator for each of the different byte-lengths of characters for the mixed tests
const mixedByteSizes = "Yח䙶𫶾eԚ疿𱺿]߉ꗫ𢆤*ɉ貸𪡑";
expect(StringUtils.substringUtf(ascii, 0, 5)).toBe("!,n~!");
expect(StringUtils.substringUtf(twoByteCharacters, 0, 5)).toBe("Āā߿܀Ā");
expect(StringUtils.substringUtf(threeByteCharacters, 0, 5)).toBe("ࠀ倀ꀀࠀ");
expect(StringUtils.substringUtf(fourByteCharacters, 0, 5)).toBe("𐀀𐔀𐨀𐿶𐀀");
expect(StringUtils.substringUtf(mixedByteSizes, 0, 5)).toBe("Yח䙶𫶾e");
expect(StringUtils.substringUtf(mixedByteSizes, 4, 4)).toBe("eԚ疿𱺿");
});
});
});