From d7bd6e6c5e06aecbe0a59a69b3e2b3416da7a81c Mon Sep 17 00:00:00 2001 From: hugoalh <32359235+hugoalh@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:20:53 +0800 Subject: [PATCH] Fix link parser --- header/link.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/header/link.ts b/header/link.ts index 5494156..51f5c08 100644 --- a/header/link.ts +++ b/header/link.ts @@ -97,7 +97,6 @@ export class HTTPHeaderLink { valueResolve.charAt(cursor) === "," ) { parameters[parameterName] = ""; - cursor += 1; break; } if (valueResolve.charAt(cursor) === ";") { @@ -128,27 +127,25 @@ export class HTTPHeaderLink { let cursorDiffParameterValue: number = valueResolve.slice(cursor).search(/[\s;,]/u); if (cursorDiffParameterValue === -1) { parameterValue += valueResolve.slice(cursor); - parameters[parameterName] = parameterValue; cursor += parameterValue.length; - break; - } - parameterValue += valueResolve.slice(cursor, cursorDiffParameterValue); - parameters[parameterName] = parameterValue; - cursor += cursorDiffParameterValue; - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - if ( - cursor === valueResolve.length || - valueResolve.charAt(cursor) === "," - ) { - cursor += 1; - break; - } - if (valueResolve.charAt(cursor) === ";") { - cursor += 1; - continue; + } else { + parameterValue += valueResolve.slice(cursor, cursorDiffParameterValue); + cursor += cursorDiffParameterValue; } - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character "," or ";", or end of the string!`); } + parameters[parameterName] = parameterValue; + cursor += cursorWhitespaceSkipper(valueResolve, cursor); + if ( + cursor === valueResolve.length || + valueResolve.charAt(cursor) === "," + ) { + break; + } + if (valueResolve.charAt(cursor) === ";") { + cursor += 1; + continue; + } + throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character "," or ";", or end of the string!`); } for (let [name, value] of Object.entries(parameters)) { if (parametersNeedLowerCaseValue.has(name)) {