Skip to content

Commit 8dea1c5

Browse files
committed
fix(parse): accept list what includes empty element
1 parent 27e50c1 commit 8dea1c5

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

_tools/meta.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ export const makeOptions = (version: string): BuildOptions => ({
3737
},
3838
packageManager: "pnpm",
3939
mappings: {
40-
"https://deno.land/x/isx@1.1.0/is_string.ts": {
40+
"https://deno.land/x/isx@1.3.1/is_string.ts": {
4141
name: "@miyauci/isx",
42-
version: "1.1.0",
43-
subPath: "is_string",
42+
version: "1.3.1",
43+
subPath: "is_string.js",
44+
},
45+
"https://deno.land/x/[email protected]/iterable/is_not_empty.ts": {
46+
name: "@miyauci/isx",
47+
version: "1.3.1",
48+
subPath: "iterable/is_not_empty.js",
4449
},
4550
"https://deno.land/x/[email protected]/token.ts": {
4651
name: "@httpland/http-utils",

deno.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22
// This module is browser compatible.
33

4-
export { isString } from "https://deno.land/x/[email protected]/is_string.ts";
4+
export { isString } from "https://deno.land/x/[email protected]/is_string.ts";
5+
export { isNotEmpty } from "https://deno.land/x/[email protected]/iterable/is_not_empty.ts";
56
export {
67
isToken,
78
type Token,

parse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22
// This module is browser compatible.
33

4-
import { isToken, parseListFields } from "./deps.ts";
4+
import { isNotEmpty, isToken, parseListFields } from "./deps.ts";
55
import { Msg } from "./constants.ts";
66
import type { AcceptRanges } from "./types.ts";
77

@@ -19,11 +19,12 @@ import type { AcceptRanges } from "./types.ts";
1919
*/
2020
export function parseAcceptRanges(input: string): AcceptRanges {
2121
const acceptableRanges = parseListFields(input);
22+
const msg = `${Msg.InvalidSyntax} "${input}"`;
23+
24+
if (!isNotEmpty(acceptableRanges)) throw new SyntaxError(msg);
2225

2326
acceptableRanges.forEach((token) => {
24-
if (!isToken(token)) {
25-
throw SyntaxError(`${Msg.InvalidSyntax} "${input}"`);
26-
}
27+
if (!isToken(token)) throw new SyntaxError(msg);
2728
});
2829

2930
return acceptableRanges as AcceptRanges;

parse_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ describe("parseAcceptRanges", () => {
1818
",",
1919
",,,",
2020
", , ,",
21-
"a,",
22-
"a, , a",
2321
"あ",
2422
"a, あ",
2523
`""`,
@@ -38,6 +36,7 @@ describe("parseAcceptRanges", () => {
3836
[" abc ", ["abc"]],
3937
["abc, def", ["abc", "def"]],
4038
["bytes,none", ["bytes", "none"]],
39+
["bytes, ,,none", ["bytes", "none"]],
4140
];
4241

4342
table.forEach(([input, expected]) => {

0 commit comments

Comments
 (0)