Skip to content

Commit

Permalink
Fix link parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Aug 4, 2023
1 parent 6fd0e15 commit d7bd6e6
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions header/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class HTTPHeaderLink {
valueResolve.charAt(cursor) === ","
) {
parameters[parameterName] = "";
cursor += 1;
break;
}
if (valueResolve.charAt(cursor) === ";") {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit d7bd6e6

Please sign in to comment.