Skip to content

Conversation

@TimothyGu
Copy link
Member

@TimothyGuTimothyGu commented Jun 26, 2017

Fixes width calculation of non-spacing marks, commonly seen in Unicode Normalization Form D. Example: 'a\u0301' ('á'.normalize('NFD')), 'ру́сский язы́к' (Unicode doesn't have many precomposed accented Cyrillic letters).

Outdated information

Not sure where to add tests for this feature though. readline has the following tests:

  • test-readline-csi.js
  • test-readline-emit-keypress-events.js
  • test-readline-interface.js
  • test-readline.js
  • test-readline-keys.js
  • test-readline-reopen.js
  • test-readline-set-raw-mode.js
  • test-readline-undefined-columns.js
  • test-icu-stringwidth.js

None of them seem to fit this bug, which is the glue between getStringWidth and readline, Hence the WIP.


The second commit changes how widths of certain characters are determined:

  • Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width
  • Categorize all spacing marks (Mc) as non-0-width.
  • Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that block.

These decisions are made, partially by following the behavior of GNOME Terminal. Testing on other terminals is of course welcome.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

readline

@nodejs-github-botnodejs-github-bot added the readline Issues and PRs related to the built-in readline module. label Jun 26, 2017
@cjihrig
Copy link
Contributor

None of them seem to fit this bug, which is the glue between getStringWidth and readline, Hence the WIP.

Why not just create a new test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the u_isdefined() check?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My terminal (GNOME Terminal) actually displays unassigned characters (in a weird box form) so they are more than 0-width. Indeed, UAX #11 specifies that

Unassigned code points in ranges intended for CJK ideographs are classified as Wide.

while

All other unassigned code points are by default classified as Neutral.

I removed the u_isdefined() check here so that these unassigned characters can use the generic ICU routine below, which does the right thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspected that was the case. Ok :)

Copy link
Member

@jasnelljasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice... thank you!

@TimothyGu
Copy link
MemberAuthor

@cjihrig

Why not just create a new test?

Err... why did I not think of that...

@TimothyGuTimothyGu changed the title WIP readline: properly handle 0-width charactersreadline: fix character width calculationJun 27, 2017
@TimothyGu
Copy link
MemberAuthor

Tests for 0-width characters are added too.

CI: https://ci.nodejs.org/job/node-test-pull-request/8836/

@Trott
Copy link
Member

Stopped the Raspberry Pi devices in Ci because they had been running for 2.5 hours and had no new console messages for over an hour. Not sure if this will self-correct or if we need Build WG intervention....

@Trott
Copy link
Member

Not looking like the Pi issue is self-correcting. Will have to either wait for the issue to get resolved before proceeding, or decide that this can land without the Pi run.
¯\(ツ)

@TimothyGu
Copy link
MemberAuthor

Will have to either wait for the issue to get resolved before proceeding, or decide that this can land without the Pi run.

Given that the other machines are universally green (except for macOS's fickle nature), nor does this PR have any architecture-specific components, I'd say this can land w/o confirmation from RPi.

- Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width - Categorize all spacing marks (Mc) as non-0-width. - Treat soft hyphens (a format character Cf) as non-0-width. - Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that character per UAX nodejs#11. - Avoid getting the General_Category of a character multiple times as it is an intensive operation. Refs: http://unicode.org/reports/tr11/
@jasnell
Copy link
Member

jasnell pushed a commit that referenced this pull request Jun 29, 2017
jasnell pushed a commit that referenced this pull request Jun 29, 2017
- Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width - Categorize all spacing marks (Mc) as non-0-width. - Treat soft hyphens (a format character Cf) as non-0-width. - Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that character per UAX #11. - Avoid getting the General_Category of a character multiple times as it is an intensive operation. Refs: http://unicode.org/reports/tr11/ PR-URL: #13918 Reviewed-By: James M Snell <[email protected]>
@jasnell
Copy link
Member

Landed in 01aeb38 and f4b5b70

@jasnelljasnell closed this Jun 29, 2017
addaleax pushed a commit that referenced this pull request Jun 29, 2017
addaleax pushed a commit that referenced this pull request Jun 29, 2017
- Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width - Categorize all spacing marks (Mc) as non-0-width. - Treat soft hyphens (a format character Cf) as non-0-width. - Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that character per UAX #11. - Avoid getting the General_Category of a character multiple times as it is an intensive operation. Refs: http://unicode.org/reports/tr11/ PR-URL: #13918 Reviewed-By: James M Snell <[email protected]>
@addaleaxaddaleax mentioned this pull request Jun 29, 2017
@TimothyGuTimothyGu deleted the readline-nsm branch June 30, 2017 06:23
addaleax pushed a commit that referenced this pull request Jul 11, 2017
addaleax pushed a commit that referenced this pull request Jul 11, 2017
- Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width - Categorize all spacing marks (Mc) as non-0-width. - Treat soft hyphens (a format character Cf) as non-0-width. - Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that character per UAX #11. - Avoid getting the General_Category of a character multiple times as it is an intensive operation. Refs: http://unicode.org/reports/tr11/ PR-URL: #13918 Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit that referenced this pull request Jul 18, 2017
addaleax pushed a commit that referenced this pull request Jul 18, 2017
- Categorize all nonspacing marks (Mn) and enclosing marks (Me) as 0-width - Categorize all spacing marks (Mc) as non-0-width. - Treat soft hyphens (a format character Cf) as non-0-width. - Do not treat all unassigned code points as 0-width; instead, let ICU select the default for that character per UAX #11. - Avoid getting the General_Category of a character multiple times as it is an intensive operation. Refs: http://unicode.org/reports/tr11/ PR-URL: #13918 Reviewed-By: James M Snell <[email protected]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readlineIssues and PRs related to the built-in readline module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@TimothyGu@cjihrig@Trott@jasnell@MylesBorins@nodejs-github-bot