trousse 2.11.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/urls.js +6 -4
  2. package/package.json +1 -1
package/dist/urls.js CHANGED
@@ -122,6 +122,8 @@ const fixMalformedScheme = (url) => {
122
122
  };
123
123
  const nestedUrlRegex = /[a-z][a-z\d+.-]*(?::|%3A)(?:\/\/|%2F%2F)|(?<=[=?&])(?:\/\/|%2F%2F)/i;
124
124
  const httpOrSchemeRelativeRegex = /^(?:https?:)?\/\//i;
125
+ const lostSeparatorRegex = /(?<!\s)\s+(?=[A-Za-z_][\w.-]*=)/g;
126
+ const slashClosedValueRegex = /(=[^&/=]+)\/+(?=&|$)/g;
125
127
  const fixMalformedQuery = (url) => {
126
128
  if (!httpOrSchemeRelativeRegex.test(url)) return url;
127
129
  const hashIndex = url.indexOf("#");
@@ -130,16 +132,15 @@ const fixMalformedQuery = (url) => {
130
132
  const fragment = hasFragment ? url.slice(hashIndex) : "";
131
133
  const authorityEnd = head.indexOf("//") + 2;
132
134
  const nestedOffset = head.slice(authorityEnd).search(nestedUrlRegex);
133
- const ownEnd = nestedOffset !== -1 ? authorityEnd + nestedOffset : head.length;
135
+ const hasNestedUrl = nestedOffset !== -1;
136
+ const ownEnd = hasNestedUrl ? authorityEnd + nestedOffset : head.length;
134
137
  const markIndex = head.indexOf("?");
135
138
  const hasMark = markIndex !== -1 && markIndex < ownEnd;
136
- const secondMarkIndex = hasMark ? head.indexOf("?", markIndex + 1) : -1;
137
- const hasSecondMark = secondMarkIndex !== -1 && secondMarkIndex < ownEnd;
138
139
  const pathIndex = head.indexOf("/", authorityEnd);
139
140
  const pathEnd = hasMark ? markIndex : ownEnd;
140
141
  const glueIndex = pathIndex !== -1 && pathIndex < pathEnd ? head.indexOf("&", pathIndex) : -1;
141
142
  const isGlued = glueIndex !== -1 && glueIndex < pathEnd;
142
- if (!isGlued && !hasSecondMark) return url;
143
+ if (!isGlued && !hasMark) return url;
143
144
  const queryIndex = isGlued ? glueIndex : markIndex;
144
145
  const queryStart = queryIndex + (isGlued && head[glueIndex + 1] === "?" ? 2 : 1);
145
146
  let query = "";
@@ -155,6 +156,7 @@ const fixMalformedQuery = (url) => {
155
156
  if (character === "=") hasValue = true;
156
157
  query += character;
157
158
  }
159
+ if (!hasNestedUrl) query = query.replace(lostSeparatorRegex, "&").replace(slashClosedValueRegex, "$1");
158
160
  return `${head.slice(0, queryIndex)}?${query}${head.slice(ownEnd)}${fragment}`;
159
161
  };
160
162
  const feedSchemes = [
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^8.1.0"
48
48
  },
49
- "version": "2.11.0"
49
+ "version": "2.11.1"
50
50
  }