mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-27 21:54:15 +00:00
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:
@@ -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Ԛ疿𱺿");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user