Skip to content

Commit c8ee900

Browse files
committed
fix(parse): fix to parsing pattern
1 parent 8046b0d commit c8ee900

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

_abnf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const challenge = sequence(
2424
suffix("+", SP),
2525
either(
2626
namedCapture("token68", token68),
27-
namedCapture("authParam", /.+/),
27+
namedCapture("authParam", /.*/),
2828
),
2929
),
3030
);
@@ -61,7 +61,7 @@ const authParam = sequence(
6161
);
6262

6363
if (import.meta.main) {
64-
console.log("challenge:", challenge);
64+
console.log("challenge:", optimize(challenge).toRegExp());
6565
console.log("element: ", element);
6666
console.log("authParam: ", optimize(authParam).toRegExp());
6767
console.log("token: ", optimize(token).toRegExp());

auth_param.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@
5757
"must_fail": true
5858
},
5959
{
60-
"name": "invalid quoted-pair",
60+
"name": "invalid quoted-pair char",
6161
"header": "a=\"\u0000\"",
6262
"must_fail": true
63+
},
64+
{
65+
"name": "invalid quoted-pair syntax",
66+
"header": "a=\"a\\\"",
67+
"must_fail": true
6368
}
6469
]

authorization.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
[
2+
{
3+
"name": "no params",
4+
"header": "A",
5+
"expected": {
6+
"authScheme": "A",
7+
"params": null
8+
}
9+
},
10+
{
11+
"name": "empty params",
12+
"header": "B ",
13+
"expected": {
14+
"authScheme": "B",
15+
"params": {}
16+
},
17+
"normalize": "B"
18+
},
219
{
320
"name": "basic",
421
"ref": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization#basic_authentication",

parse.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { head, isString, toLowerCase } from "./deps.ts";
66
import { Msg } from "./constants.ts";
77
import type { Authorization, AuthParams } from "./types.ts";
88

9+
/** Generate from _abnf.ts. */
910
const reAuthorization =
10-
/^(?<authScheme>[!#$%&'*+.^_`|~\dA-Za-z-]+)(?: +(?:(?<token68>(?:[A-Za-z]|\d|[-._~+/])+=*)|(?<authParam>.+)))?$/;
11+
/^(?<authScheme>[\w!#$%&'*+.^`|~-]+)(?: +(?:(?<token68>(?:[A-Za-z]|\d|[+./_~-])+=*)|(?<authParam>.*)))?$/;
1112

1213
/** Parse string into {@link Authorization}.
1314
*
@@ -57,6 +58,7 @@ type ParsedGroups = {
5758
readonly authParam: string | undefined;
5859
};
5960

61+
/** Generate from _abnf.ts. */
6062
const reAuthParam =
6163
/^(?<key>[\w!#$%&'*+.^`|~-]+)[\t ]*=[\t ]*(?:(?<token>[\w!#$%&'*+.^`|~-]+)|(?<quotedString>"(?:\t| |!|[ \x23-\x5B\x5D-\x7E]|[\x80-\xFF]|\\(?:\t| |[\x21-\x7E]|[\x80-\xFF]))*"))$/;
6264

stringify_test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ describe("stringifyAuthorization", () => {
5151
authorization.forEach((suite) => {
5252
it(suite.name, () => {
5353
if (!suite.must_fail) {
54+
const input = suite.normalize ?? suite.header;
55+
5456
assertEquals(
5557
stringifyAuthorization(suite.expected as Authorization),
56-
suite.header,
58+
input,
5759
);
5860
}
5961
});

0 commit comments

Comments
 (0)