Skip to content

Commit 2bf677c

Browse files
fix(util-endpoints): reject non-ASCII input in substring per Smithy spec (#1880)
1 parent 026b177 commit 2bf677c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.changeset/ten-lobsters-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/util-endpoints": minor
3+
---
4+
5+
return empty when given non-ASCII input in substring

packages/util-endpoints/src/lib/substring.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe(substring.name, () => {
1212
it("when input.length < stop", () => {
1313
expect(substring("", 0, 1, false)).toBeNull();
1414
});
15+
16+
it("when input contains non-ASCII characters", () => {
17+
expect(substring("abc\u0080", 0, 3, false)).toBeNull();
18+
expect(substring("abcé", 0, 3, false)).toBeNull();
19+
expect(substring("ab日c", 0, 3, false)).toBeNull();
20+
});
1521
});
1622

1723
it("returns substring", () => {

packages/util-endpoints/src/lib/substring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* The length of the returned string will always be stop-start.
66
*/
77
export const substring = (input: string, start: number, stop: number, reverse: boolean): string | null => {
8-
if (start >= stop || input.length < stop) {
8+
if (start >= stop || input.length < stop || /[^\u0000-\u007f]/.test(input)) {
99
return null;
1010
}
1111
if (!reverse) {

0 commit comments

Comments
 (0)