fix(Text To Unicode): fix python \U padded to 8 for high ucods

Fix #196
This commit is contained in:
ShareVB committed 2025-10-04 21:31:23 +02:00
1 parent 282acba77e
commit a47e25a360
2 files changed
+3 -3

No files matched your search

@@ -11,7 +11,7 @@ describe('text-to-unicode', () => {
expect(convertTextToUnicode('💩 AĀ', { encoding: 'htmldec' })).toBe('💩 AĀ');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'htmlhex' })).toBe('💩 AĀ');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'uniplus' })).toBe('U+1f4a9 U+00020 U+00041 U+00100');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'python' })).toBe('\\U1f4a9\\x20\\x41\\u0100');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'python' })).toBe('\\U0001f4a9\\x20\\x41\\u0100');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'js' })).toBe('\\u{1f4a9}\\u0020\\u0041\\u0100');
expect(convertTextToUnicode('💩 AĀ', { encoding: 'utf16' })).toBe('\\ud83d\\udca9\\u0020\\u0041\\u0100');
expect(convertTextToUnicode('💩 hello AĀ', { skipAscii: true })).toBe('💩 hello AĀ');
@@ -29,7 +29,7 @@ describe('text-to-unicode', () => {
expect(convertUnicodeToText('💩 AĀ')).toBe('💩 AĀ');
expect(convertUnicodeToText('💩 AĀ')).toBe('💩 AĀ');
expect(convertUnicodeToText('U+1f4a9 U+00020 U+00041 U+00100')).toBe('💩 AĀ');
expect(convertUnicodeToText('\\U1f4a9\\x20\\x41\\u0100')).toBe('💩 AĀ');
expect(convertUnicodeToText('\\U0001f4a9\\x20\\x41\\u0100')).toBe('💩 AĀ');
expect(convertUnicodeToText('\\u{1f4a9}\\u0020\\u0041\\u0100')).toBe('💩 AĀ');
expect(convertUnicodeToText('\\ud83d\\udca9\\u0020\\u0041\\u0100')).toBe('💩 AĀ');
expect(convertUnicodeToText('\\01f4a9 AĀ')).toBe('💩 AĀ');
@@ -34,7 +34,7 @@ function convertTextToUnicode(text: string, { encoding = 'htmldec', skipAscii =
}
else if (encoding === 'python') {
prefix = (value: number) => value < 256 ? '\\x' : (value < 65536 ? '\\u' : '\\U');
padding = (value: number) => value < 256 ? 2 : 4;
padding = (value: number) => value < 256 ? 2 : (value < 65536 ? 4 : 8);
}
else if (encoding === 'js') {
prefix = (value: number) => value < 65536 ? '\\u' : '\\u{';