Skip to content

Write a Char's \u escape with its own four hexits - #730

Closed
lagergren wants to merge 1 commit into
masterfrom
lagergren/fix-char-escape-hexits
Closed

lagergren wants to merge 1 commit into
masterfrom
lagergren/fix-char-escape-hexits

Conversation

@lagergren

Copy link
Copy Markdown
Contributor

Summary

On master, Char.appendEscaped() writes the wrong \u escape for every character it escapes that way, apart from those below U+0010: U+2028 comes out as \u0008, U+0085 as \u0005 and U+001F as \u000F. Char.quoted(), String.quoted() and String.appendEscaped() write their escapes through it.

Root cause

Each hexit was (codepoint & 0xF000 >>> 24).toHexit(), and so on for the others. In Ecstasy, shifts and & have the same precedence and group left to right, so that is (codepoint & 0xF000) >>> 24, which is 0 for every character this escapes: the C0 and C1 control characters with no escape of their own, and U+2028 and U+2029. The shifts were also twice what they should be. Only the last hexit, (codepoint & 0x000F) >>> 0, was right.

Change

Each hexit is the code point shifted by 12, 8, 4 or 0, masked to four bits.

Validation

master this branch
U+0001 '\u0001' '\u0001'
U+001F '\u000F' '\u001F'
U+0085 '\u0005' '\u0085'
U+2028 '\u0008' '
'
"a", U+2029, "b" "a\u0009b" "a
b"
  • A new testEscapes() in manualTests' literals.x asserts the table's quoted forms. CI runs it as TestLiterals. With master's Char.x it fails at its second assert, U+001F.
  • check passes, with the Ecstasy library tests; :javatools:test passes 456 tests, the 42 existing skips; TestLiterals passes through manualTests:runOne.

Limits

lagergren added a commit that referenced this pull request Oct 26, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.

@ggleyzer ggleyzer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why don't you merge this with #729?

@lagergren

Copy link
Copy Markdown
Contributor Author

@ggleyzer #729 is an issue, not a PR. It asks whether an escaped backslash should stop a \u after it from being read as a Unicode escape. Today doc/x.md says it should not, so changing that is a language decision before it is a code change.

This PR fixes a bug either way: Char.appendEscaped() wrote the wrong hexits for every \u escape it produced, whatever the lexer then does with them. If #729 is decided in favor of changing the lexer, that change can come on its own with the spec change, and the only thing it would touch here is the test, which joins its expected texts from two literals because of the behavior #729 asks about.

@ggleyzer

Copy link
Copy Markdown
Collaborator

Sorry, I meant #724

lagergren added a commit that referenced this pull request Oct 26, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
Char.appendEscaped() writes a C0 or C1 control character with no escape
of its own, or a line or paragraph separator, as a backslash, a "u" and
four hexits. Each hexit was computed as (codepoint & 0xF000 >>> 24),
(codepoint & 0x0F00 >>> 16) and so on. Shifts and & have the same
precedence in Ecstasy, left to right, so that is
(codepoint & 0xF000) >>> 24: zero for every character it escapes, and
the shifts were twice too large anyway. Only the last hexit was right,
so U+2028 was written as \u0008, U+0085 as \u0005 and U+001F as \u000F,
while U+0001 came out right by accident. Each hexit is now the code
point shifted by 12, 8, 4 or 0, masked to four bits.

Char.quoted(), String.quoted() and String.appendEscaped() write their
escapes through it.

Test: a new testEscapes() in manualTests' literals.x, which CI runs as
TestLiterals, asserts the quoted forms of U+0001, U+001F, U+0085, U+2028
and a String holding U+2029. Each expected text is joined from two
literals, since the compiler reads a backslash, a "u" and four hexits as
the character they name anywhere in the source, also after an escaped
backslash; that is issue #729.
@lagergren

Copy link
Copy Markdown
Contributor Author

Combined into #724, as @ggleyzer suggested: #724 now has this PR's commit as well, and its description covers both fixes. Closing this one.

@lagergren lagergren closed this Oct 26, 2026
lagergren added a commit that referenced this pull request Oct 27, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Oct 28, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Oct 28, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Oct 29, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Oct 29, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Oct 29, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 2, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 4, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 5, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 9, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 11, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 22, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 25, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 25, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 25, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 26, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 26, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 27, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
lagergren added a commit that referenced this pull request Nov 28, 2026
docs/remaining.md's master candidates now name the pull requests for
the two library bugs found while fixing #723 and #724: #730 writes a
Char's \u escape with its own four hexits, and #731 gives a Nibble one
byte as its bytes and makes a Nibble from one. Issue #729 asks whether
an escaped backslash should keep a \u after it from being a Unicode
escape, which #730's test has to work around.

Validation: records only; the pull requests carry their own.

Limits: none.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants