-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pass-style)!: only well-formed strings are passable
- Loading branch information
Showing
5 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
User-visible changes in `@endo/pass-style`: | ||
|
||
# next release | ||
|
||
- Previously, all JavaScript strings were considered Passable with `passStyleOf(str) === 'string'`. Now, only well-formed Unicode strings are considered Passable. For all others, `passStyleOf(str)` throws a diagnostic error. This brings us into closer conformance to the OCapN standard, which prohibits sending non-well-formed strings, and requires non-well-formed strings to be rejected when received. Applications that had previously handled non-well-formed strings successfully (even if inadvertantly) may now start experiences these failure. | ||
- Exports `isWellFormedString` and `assertWellFormedString`. Unfortunately the [standard `String.prototype.isWellFormed`](https://tc39.es/proposal-is-usv-string/) first coerces its input to string, leading it to claim that some non-strings are well-formed strings. By contrast, `isWellFormedString` and `assertWellFormedString` will not judge any non-strings to be well-formed strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-disable no-useless-concat */ | ||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
import { | ||
passStyleOf, | ||
isWellFormedString, | ||
assertWellFormedString, | ||
} from '../src/passStyleOf.js'; | ||
|
||
test('test string well formedness behaviors', t => { | ||
const gcleff1 = '\u{1D11E}'; | ||
const gcleff2 = '\u{D834}\u{DD1E}'; | ||
const gcleff3 = '\u{D834}' + '\u{DD1E}'; | ||
const badcleff1 = '\u{D834}\u{D834}\u{DD1E}'; | ||
const badcleff2 = '\u{D834}\u{DD1E}\u{D834}'; | ||
const badcleff3 = '\u{D834}' + '\u{DD1E}\u{D834}'; | ||
|
||
// This test block ensures that the underlying platform behaves as we expect | ||
t.is(gcleff1, gcleff2); | ||
t.is(gcleff1, gcleff3); | ||
t.is(gcleff1.length, 2); | ||
t.is(gcleff2.length, 2); | ||
t.is(gcleff3.length, 2); | ||
// Uses string iterator, which iterates code points if possible, not | ||
// UTF16 code units | ||
t.deepEqual([...gcleff1], [gcleff1]); | ||
t.not(badcleff1, badcleff2); | ||
t.is(badcleff2, badcleff3); | ||
t.is(badcleff1.length, 3); | ||
// But if the string contains lone surrogates, the string iterator will | ||
// produce those as characters | ||
t.deepEqual([...badcleff1], ['\u{D834}', gcleff1]); | ||
t.deepEqual([...badcleff2], [gcleff1, '\u{D834}']); | ||
|
||
t.is(passStyleOf(gcleff1), 'string'); | ||
t.true(isWellFormedString(gcleff1)); | ||
t.notThrows(() => assertWellFormedString(gcleff1)); | ||
|
||
t.throws(() => passStyleOf(badcleff1), { | ||
message: 'Expected well-formed unicode string: "\\ud834𝄞"', | ||
}); | ||
t.throws(() => passStyleOf(badcleff2), { | ||
message: 'Expected well-formed unicode string: "𝄞\\ud834"', | ||
}); | ||
t.false(isWellFormedString(badcleff1)); | ||
t.false(isWellFormedString(badcleff2)); | ||
t.throws(() => assertWellFormedString(badcleff1), { | ||
message: 'Expected well-formed unicode string: "\\ud834𝄞"', | ||
}); | ||
t.throws(() => assertWellFormedString(badcleff2), { | ||
message: 'Expected well-formed unicode string: "𝄞\\ud834"', | ||
}); | ||
}); |