File tree Expand file tree Collapse file tree 4 files changed +13
-10
lines changed Expand file tree Collapse file tree 4 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export { isString } from "https://deno.land/x/isx@1.1.1/is_string.ts";
1313export { isNumber } from "https://deno.land/x/isx@1.1.1/is_number.ts" ;
1414export { isNegativeNumber } from "https://deno.land/x/isx@1.1.1/number/is_negative_number.ts" ;
1515export { isValidDate } from "https://deno.land/x/isx@1.1.1/date/is_valid_date.ts" ;
16+ export { trim } from "https://deno.land/x/prelude_js@1.0.0/trim.ts" ;
1617export {
1718 type Handler ,
1819 type Middleware ,
Original file line number Diff line number Diff line change 33
44// TODO(miyauci): External Packaging
55
6- import { type ETag , parseETag } from "./deps.ts" ;
6+ import { type ETag , parseETag , trim } from "./deps.ts" ;
77
88export type IfMatch = Star | ETag [ ] ;
99export type IfNoneMatch = IfMatch ;
@@ -13,12 +13,11 @@ export type Star = "*";
1313 * @throws {SyntaxError } If the input is invalid.
1414 */
1515export function parse ( input : string ) : IfMatch | IfNoneMatch {
16- input = input . trim ( ) ;
17-
1816 if ( input === "*" ) return input ;
1917
2018 return input
2119 . split ( "," )
20+ . map ( trim )
2221 . filter ( Boolean )
2322 . map ( parseETag ) ;
2423}
Original file line number Diff line number Diff line change @@ -6,9 +6,6 @@ describe("parse", () => {
66 it ( "should return star" , ( ) => {
77 const table : string [ ] = [
88 "*" ,
9- " *" ,
10- "* " ,
11- " * " ,
129 ] ;
1310
1411 table . forEach ( ( input ) => {
@@ -20,6 +17,8 @@ describe("parse", () => {
2017 const table : string [ ] = [
2118 "" ,
2219 " " ,
20+ " , " ,
21+ ", , ," ,
2322 ] ;
2423
2524 table . forEach ( ( input ) => {
@@ -62,6 +61,10 @@ describe("parse", () => {
6261 `* *` ,
6362 `**` ,
6463 `"", *` ,
64+ " *" ,
65+ "* " ,
66+ " * " ,
67+ "a," ,
6568 ] ;
6669
6770 table . forEach ( ( input ) => {
Original file line number Diff line number Diff line change @@ -50,13 +50,13 @@ export function ifModifiedSince(
5050 fieldValue : string ,
5151 lastModified : string ,
5252) : boolean {
53- const date = parseHttpDate ( fieldValue . trim ( ) ) ;
53+ const date = parseHttpDate ( fieldValue ) ;
5454
5555 if ( ! isValidDate ( date ) ) {
5656 throw SyntaxError ( Msg . InvalidField ) ;
5757 }
5858
59- const lastMod = parseHttpDate ( lastModified . trim ( ) ) ;
59+ const lastMod = parseHttpDate ( lastModified ) ;
6060
6161 if ( ! isValidDate ( lastMod ) ) {
6262 throw SyntaxError ( Msg . InvalidLastModified ) ;
@@ -75,13 +75,13 @@ export function ifUnmodifiedSince(
7575 fieldValue : string ,
7676 lastModified : string ,
7777) : boolean {
78- const date = parseHttpDate ( fieldValue . trim ( ) ) ;
78+ const date = parseHttpDate ( fieldValue ) ;
7979
8080 if ( ! isValidDate ( date ) ) {
8181 throw SyntaxError ( Msg . InvalidField ) ;
8282 }
8383
84- const lastMod = parseHttpDate ( lastModified . trim ( ) ) ;
84+ const lastMod = parseHttpDate ( lastModified ) ;
8585
8686 if ( ! isValidDate ( lastMod ) ) {
8787 throw SyntaxError ( Msg . InvalidLastModified ) ;
You can’t perform that action at this time.
0 commit comments