Skip to content

Commit

Permalink
util: support Combining Diacritical Marks for Symbols
Browse files Browse the repository at this point in the history
This adds support for the "Combining Diacritical Marks for Symbols"
unicode group to calculate a zero length width even if Node.js is
built without ICU.

Signed-off-by: Ruben Bridgewater <[email protected]>

PR-URL: #33650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
BridgeAR authored and codebytere committed Jun 27, 2020
1 parent 4323346 commit 91d0d53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,8 @@ if (internalBinding('config').hasIntl) {
(code > 0x7F && code <= 0x9F) || // C1 control codes
(code >= 0x300 && code <= 0x36F) || // Combining Diacritical Marks
(code >= 0x200B && code <= 0x200F) || // Modifying Invisible Characters
// Combining Diacritical Marks for Symbols
(code >= 0x20D0 && code <= 0x20FF) ||
(code >= 0xFE00 && code <= 0xFE0F) || // Variation Selectors
(code >= 0xFE20 && code <= 0xFE2F) || // Combining Half Marks
(code >= 0xE0100 && code <= 0xE01EF); // Variation Selectors
Expand Down
21 changes: 6 additions & 15 deletions test/parallel/test-readline-position.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { internalBinding } = require('internal/test/binding');
const { PassThrough } = require('stream');
const readline = require('readline');
const assert = require('assert');
Expand All @@ -21,22 +20,14 @@ common.skipIfDumbTerminal();
const tests = [
[1, 'a'],
[2, 'ab'],
[2, '丁']
[2, '丁'],
[0, '\u0301'], // COMBINING ACUTE ACCENT
[1, 'a\u0301'], // á
[0, '\u20DD'], // COMBINING ENCLOSING CIRCLE
[2, 'a\u20DDb'], // a⃝b
[0, '\u200E'], // LEFT-TO-RIGHT MARK
];

// The non-ICU JS implementation of character width calculation is only aware
// of the wide/narrow distinction. Only test these more advanced cases when
// ICU is available.
if (internalBinding('config').hasIntl) {
tests.push(
[0, '\u0301'], // COMBINING ACUTE ACCENT
[1, 'a\u0301'], // á
[0, '\u20DD'], // COMBINING ENCLOSING CIRCLE
[2, 'a\u20DDb'], // a⃝b
[0, '\u200E'] // LEFT-TO-RIGHT MARK
);
}

for (const [cursor, string] of tests) {
rl.write(string);
assert.strictEqual(rl.getCursorPos().cols, cursor);
Expand Down

0 comments on commit 91d0d53

Please sign in to comment.