@pathmode/mcp-server 1.20.1 → 1.20.2

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.
package/dist/index.js CHANGED
@@ -35783,6 +35783,7 @@ function State(input, options) {
35783
35783
  this.legacy = options['legacy'] || false;
35784
35784
  this.json = options['json'] || false;
35785
35785
  this.listener = options['listener'] || null;
35786
+ this.maxTotalMergeKeys = typeof options['maxTotalMergeKeys'] === 'number' ? options['maxTotalMergeKeys'] : 10000;
35786
35787
 
35787
35788
  this.implicitTypes = this.schema.compiledImplicit;
35788
35789
  this.typeMap = this.schema.compiledTypeMap;
@@ -35792,6 +35793,7 @@ function State(input, options) {
35792
35793
  this.line = 0;
35793
35794
  this.lineStart = 0;
35794
35795
  this.lineIndent = 0;
35796
+ this.totalMergeKeys = 0;
35795
35797
 
35796
35798
  this.documents = [];
35797
35799
 
@@ -35910,6 +35912,14 @@ function captureSegment(state, start, end, checkJson) {
35910
35912
  }
35911
35913
  }
35912
35914
 
35915
+ function chargeMergeWork(state) {
35916
+ state.totalMergeKeys += 1;
35917
+
35918
+ if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) {
35919
+ throwError(state, 'merge keys exceeded maxTotalMergeKeys (' + state.maxTotalMergeKeys + ')');
35920
+ }
35921
+ }
35922
+
35913
35923
  function mergeMappings(state, destination, source, overridableKeys) {
35914
35924
  var sourceKeys, key, index, quantity;
35915
35925
 
@@ -35917,11 +35927,16 @@ function mergeMappings(state, destination, source, overridableKeys) {
35917
35927
  throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
35918
35928
  }
35919
35929
 
35930
+ // Count the source mapping itself to bound sequences of empty mappings.
35931
+ chargeMergeWork(state);
35932
+
35920
35933
  sourceKeys = Object.keys(source);
35921
35934
 
35922
35935
  for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
35923
35936
  key = sourceKeys[index];
35924
35937
 
35938
+ chargeMergeWork(state);
35939
+
35925
35940
  if (!_hasOwnProperty.call(destination, key)) {
35926
35941
  setProperty(destination, key, source[key]);
35927
35942
  overridableKeys[key] = true;
@@ -35965,6 +35980,10 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
35965
35980
 
35966
35981
  if (keyTag === 'tag:yaml.org,2002:merge') {
35967
35982
  if (Array.isArray(valueNode)) {
35983
+ if (valueNode.length > 100) {
35984
+ throwError(state, 'abnormal merge sequence size');
35985
+ }
35986
+
35968
35987
  for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
35969
35988
  mergeMappings(state, _result, valueNode[index], overridableKeys);
35970
35989
  }
@@ -38504,7 +38523,7 @@ var _toString = Object.prototype.toString;
38504
38523
  function resolveYamlOmap(data) {
38505
38524
  if (data === null) return true;
38506
38525
 
38507
- var objectKeys = [], index, length, pair, pairKey, pairHasKey,
38526
+ var objectKeys = {}, index, length, pair, pairKey, pairHasKey,
38508
38527
  object = data;
38509
38528
 
38510
38529
  for (index = 0, length = object.length; index < length; index += 1) {
@@ -38522,8 +38541,8 @@ function resolveYamlOmap(data) {
38522
38541
 
38523
38542
  if (!pairHasKey) return false;
38524
38543
 
38525
- if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
38526
- else return false;
38544
+ if (_hasOwnProperty.call(objectKeys, pairKey)) return false;
38545
+ Object.defineProperty(objectKeys, pairKey, { value: true });
38527
38546
  }
38528
38547
 
38529
38548
  return true;
@@ -39199,6 +39218,7 @@ module.exports = function(str) {
39199
39218
  * the results in as plain data.
39200
39219
  */
39201
39220
  Object.defineProperty(exports, "__esModule", ({ value: true }));
39221
+ exports.renderOutcomeMeasurementDefinition = renderOutcomeMeasurementDefinition;
39202
39222
  exports.toSerializableChecks = toSerializableChecks;
39203
39223
  exports.renderAuthorizationGateText = renderAuthorizationGateText;
39204
39224
  exports.renderConfirmationsBody = renderConfirmationsBody;
@@ -39226,6 +39246,24 @@ function yamlScalar(value) {
39226
39246
  function outcomeOf(o) {
39227
39247
  return typeof o === 'string' ? { text: o } : o;
39228
39248
  }
39249
+ /** Compact, provider-neutral wording shared by every agent-facing export. */
39250
+ function renderOutcomeMeasurementDefinition(measurement) {
39251
+ if (!measurement)
39252
+ return '';
39253
+ const { source, expectation, window } = measurement;
39254
+ const target = `${expectation.operator} ${expectation.target}${expectation.unit ? ` ${expectation.unit}` : ''}`;
39255
+ const windowValue = window.kind === 'rolling'
39256
+ ? `${window.kind} ${window.duration}`
39257
+ : window.kind === 'fixed'
39258
+ ? `${window.kind} ${window.start}..${window.end}`
39259
+ : window.kind;
39260
+ return [
39261
+ `measure via ${source.provider} ${source.queryRef.kind}:${source.queryRef.id}`,
39262
+ measurement.resultSelector ? `select ${measurement.resultSelector}` : '',
39263
+ `target ${target}`,
39264
+ `window ${windowValue}`,
39265
+ ].filter(Boolean).join('; ');
39266
+ }
39229
39267
  function constraintOf(c) {
39230
39268
  return typeof c === 'string' ? { text: c } : c;
39231
39269
  }
@@ -39337,9 +39375,14 @@ function renderConfirmationsBody(records) {
39337
39375
  */
39338
39376
  const FRONTMATTER_ORDER = [
39339
39377
  'id', 'version', 'status', 'readiness', 'source', 'specVersion',
39340
- 'origin', 'authorization', 'authorizationNote', 'evidence', 'space', 'severity', 'created', 'updated',
39378
+ 'origin', 'authorization', 'authorizationNote', 'outcomeMeasurements',
39379
+ 'evidence', 'space', 'severity', 'created', 'updated',
39341
39380
  ];
39342
39381
  function serializeIntentMd(spec, opts = {}) {
39382
+ const outcomeMeasurements = (spec.outcomes || [])
39383
+ .map(outcomeOf)
39384
+ .map((outcome, index) => outcome.measurement ? { outcome: index, ...outcome.measurement } : null)
39385
+ .filter((entry) => entry !== null);
39343
39386
  const values = {
39344
39387
  id: spec.id,
39345
39388
  version: opts.version && opts.version >= 1 ? opts.version : 1,
@@ -39358,6 +39401,9 @@ function serializeIntentMd(spec, opts = {}) {
39358
39401
  authorizationNote: opts.origin === 'agent' && nonEmpty(opts.authorizationNote)
39359
39402
  ? opts.authorizationNote.replace(/\s+/g, ' ').trim()
39360
39403
  : undefined,
39404
+ // Body outcomes stay plain, interoperable list items. The optional recipe is a generic
39405
+ // extension in frontmatter, keyed by outcome position so old readers simply ignore it.
39406
+ outcomeMeasurements: outcomeMeasurements.length ? outcomeMeasurements : undefined,
39361
39407
  evidence: opts.evidence?.length || undefined,
39362
39408
  space: opts.space?.name,
39363
39409
  severity: opts.severity,
@@ -39369,7 +39415,10 @@ function serializeIntentMd(spec, opts = {}) {
39369
39415
  // crash rather than an omitted key.
39370
39416
  const yamlLines = FRONTMATTER_ORDER
39371
39417
  .filter(key => values[key] !== undefined && values[key] !== null && values[key] !== '')
39372
- .map(key => `${key}: ${yamlScalar(values[key])}`)
39418
+ .map(key => {
39419
+ const value = values[key];
39420
+ return `${key}: ${typeof value === 'object' ? JSON.stringify(value) : yamlScalar(value)}`;
39421
+ })
39373
39422
  .join('\n');
39374
39423
  const sections = ['---', yamlLines, '---', ''];
39375
39424
  // Directly under the frontmatter: the `authorization` key is machine-readable, but the body
@@ -40445,6 +40494,9 @@ function getPriorityLabel(o) {
40445
40494
  return '';
40446
40495
  return `[${o.priority.toUpperCase()}] `;
40447
40496
  }
40497
+ function getOutcomeMeasurement(o) {
40498
+ return typeof o === 'string' ? '' : (0, serializeIntentMd_1.renderOutcomeMeasurementDefinition)(o.measurement);
40499
+ }
40448
40500
  function getLiveQualityCheckPromptBlock() {
40449
40501
  return `LIVE QUALITY CHECKS:
40450
40502
  - After EVERY meaningful user answer, silently update your current draft and run a quality pass before asking the next question.
@@ -40631,6 +40683,9 @@ function formatCursorRules(spec) {
40631
40683
  sections.push('Your implementation MUST satisfy ALL of these:');
40632
40684
  for (const outcome of spec.outcomes) {
40633
40685
  sections.push(`- ${getPriorityLabel(outcome)}${getOutcomeText(outcome)}`);
40686
+ const measurement = getOutcomeMeasurement(outcome);
40687
+ if (measurement)
40688
+ sections.push(` - measurement: ${measurement}`);
40634
40689
  }
40635
40690
  }
40636
40691
  if (spec.scope?.inScope?.length || spec.scope?.outOfScope?.length) {
@@ -40711,7 +40766,10 @@ function formatClaudeMdSection(spec) {
40711
40766
  sections.push(...decisionLines(spec.decisions, '**Decisions**:'));
40712
40767
  if (spec.outcomes?.length) {
40713
40768
  sections.push('**Outcomes**:');
40714
- sections.push(spec.outcomes.map(o => `- [ ] ${getPriorityLabel(o)}${getOutcomeText(o)}`).join('\n'));
40769
+ sections.push(spec.outcomes.map(o => {
40770
+ const measurement = getOutcomeMeasurement(o);
40771
+ return `- [ ] ${getPriorityLabel(o)}${getOutcomeText(o)}${measurement ? `\n - measurement: ${measurement}` : ''}`;
40772
+ }).join('\n'));
40715
40773
  }
40716
40774
  if (spec.scope?.inScope?.length || spec.scope?.outOfScope?.length) {
40717
40775
  const scopeParts = ['**Scope**:'];
@@ -40866,6 +40924,9 @@ function buildGraderRubric(spec, opts = {}) {
40866
40924
  for (const o of outcomes) {
40867
40925
  const bar = priorityToBar(getOutcomePriority(o));
40868
40926
  sections.push(`${i}. [${bar}] ${getOutcomeText(o)}`);
40927
+ const measurement = getOutcomeMeasurement(o);
40928
+ if (measurement)
40929
+ sections.push(` - Production signal: ${measurement}`);
40869
40930
  sections.push(' - Evidence: point to the specific value, state, or test result in the artifact that proves this. If you cannot, mark FAIL.');
40870
40931
  i++;
40871
40932
  }
@@ -41071,6 +41132,7 @@ exports.stripHtmlComments = stripHtmlComments;
41071
41132
  const fs_1 = __importDefault(__nccwpck_require__(9896));
41072
41133
  const path_1 = __importDefault(__nccwpck_require__(6928));
41073
41134
  const gray_matter_1 = __importDefault(__nccwpck_require__(9599));
41135
+ const measurement_schema_1 = __nccwpck_require__(1635);
41074
41136
  const CONFIRMATION_HEADER_RE = /^\*\*(objective|outcomes)\*\*\s*[—–-]\s*(confirmed|waived)\s+by\s+(agent|human)\s*$/i;
41075
41137
  const CONFIRMATION_FIELD_RE = /^\s*[-*]\s+(actor|problem|outcome|observable|reason|anchor|at)\s*:\s*(.+)$/i;
41076
41138
  /**
@@ -41198,6 +41260,22 @@ function preferSection(fromSection, fromFrontmatter) {
41198
41260
  .map((v) => v.trim())
41199
41261
  .filter(Boolean);
41200
41262
  }
41263
+ function attachOutcomeMeasurements(outcomes, rawEntries) {
41264
+ if (!Array.isArray(rawEntries))
41265
+ return outcomes;
41266
+ const definitions = new Map();
41267
+ for (const raw of rawEntries) {
41268
+ const parsed = measurement_schema_1.outcomeMeasurementEntryShape.safeParse(raw);
41269
+ if (!parsed.success || parsed.data.outcome >= outcomes.length)
41270
+ continue;
41271
+ const { outcome, ...definition } = parsed.data;
41272
+ definitions.set(outcome, definition);
41273
+ }
41274
+ return outcomes.map((text, index) => {
41275
+ const measurement = definitions.get(index);
41276
+ return measurement ? { text, measurement } : text;
41277
+ });
41278
+ }
41201
41279
  /** Coerce a structured frontmatter entry ({text}, {description}) to its text, else ''. */
41202
41280
  function coerceItemText(v) {
41203
41281
  if (!v || typeof v !== 'object')
@@ -41250,7 +41328,7 @@ function parseIntentMarkdown(content, fallbackId = 'intent') {
41250
41328
  title: data.title || data.userGoal || extractTitle(body) || 'Untitled Intent',
41251
41329
  stageName: data.stage || undefined,
41252
41330
  severity: data.severity || undefined,
41253
- outcomes: preferSection(extractListSection(sections, 'Outcomes'), data.outcomes),
41331
+ outcomes: attachOutcomeMeasurements(preferSection(extractListSection(sections, 'Outcomes'), data.outcomes), data.outcomeMeasurements),
41254
41332
  decisions: extractDecisions(sections),
41255
41333
  constraints: preferSection(extractListSection(sections, 'Constraints'), data.constraints),
41256
41334
  edgeCases: (() => { const fromBody = extractEdgeCases(sections); return fromBody.length ? fromBody : frontmatterEdgeCases(data.edgeCases); })(),
@@ -41589,7 +41667,7 @@ function hasVerificationContent(v) {
41589
41667
  * units and source labels.
41590
41668
  */
41591
41669
  Object.defineProperty(exports, "__esModule", ({ value: true }));
41592
- exports.recordOutcomeMeasurementInputSchema = exports.provenanceShape = exports.expectationShape = exports.windowShape = exports.queryRefShape = exports.windowKindEnum = exports.comparatorEnum = void 0;
41670
+ exports.recordOutcomeMeasurementInputSchema = exports.provenanceShape = exports.outcomeMeasurementEntryShape = exports.outcomeMeasurementDefinitionShape = exports.expectationShape = exports.windowShape = exports.queryRefShape = exports.windowKindEnum = exports.comparatorEnum = void 0;
41593
41671
  exports.outcomeSelectorError = outcomeSelectorError;
41594
41672
  const zod_1 = __nccwpck_require__(924);
41595
41673
  const MAX_TEXT = 500;
@@ -41626,6 +41704,19 @@ exports.expectationShape = zod_1.z.object({
41626
41704
  target: zod_1.z.number().finite(),
41627
41705
  unit: zod_1.z.string().trim().max(MAX_UNIT).optional(),
41628
41706
  });
41707
+ /** Mirrors the optional query recipe stored on a StructuredOutcome. */
41708
+ exports.outcomeMeasurementDefinitionShape = zod_1.z.object({
41709
+ source: zod_1.z.object({
41710
+ provider: zod_1.z.string().trim().min(1).max(MAX_SHORT).describe('System that owns the saved query, e.g. "posthog"'),
41711
+ queryRef: exports.queryRefShape,
41712
+ }),
41713
+ resultSelector: zod_1.z.string().trim().min(1).max(MAX_TEXT).optional().describe('Optional path into a compound provider response'),
41714
+ expectation: exports.expectationShape,
41715
+ window: exports.windowShape,
41716
+ });
41717
+ exports.outcomeMeasurementEntryShape = exports.outcomeMeasurementDefinitionShape.extend({
41718
+ outcome: zod_1.z.number().int().nonnegative(),
41719
+ });
41629
41720
  exports.provenanceShape = zod_1.z.object({
41630
41721
  provider: zod_1.z.string().trim().min(1).max(MAX_SHORT).describe('System the number came from, e.g. "posthog"'),
41631
41722
  queryRef: exports.queryRefShape,
@@ -50110,9 +50201,24 @@ exports.AjvJsonSchemaValidator = AjvJsonSchemaValidator;
50110
50201
  "use strict";
50111
50202
 
50112
50203
 
50113
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = __nccwpck_require__(5077)
50204
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = __nccwpck_require__(5077)
50114
50205
  const { SCHEMES, getSchemeHandler } = __nccwpck_require__(5300)
50115
50206
 
50207
+ const VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u
50208
+ const MALFORMED_SCHEME_ERROR = 'URI scheme is malformed.'
50209
+
50210
+ /**
50211
+ * @param {string} scheme
50212
+ * @returns {string}
50213
+ */
50214
+ function decodeValidScheme (scheme) {
50215
+ const decodedScheme = unescape(String(scheme))
50216
+ if (!VALID_SCHEME.test(decodedScheme)) {
50217
+ throw new TypeError(MALFORMED_SCHEME_ERROR)
50218
+ }
50219
+ return decodedScheme
50220
+ }
50221
+
50116
50222
  /**
50117
50223
  * @template {import('./types/index').URIComponent|string} T
50118
50224
  * @param {T} uri
@@ -50121,7 +50227,7 @@ const { SCHEMES, getSchemeHandler } = __nccwpck_require__(5300)
50121
50227
  */
50122
50228
  function normalize (uri, options) {
50123
50229
  if (typeof uri === 'string') {
50124
- uri = /** @type {T} */ (serialize(parse(uri, options), options))
50230
+ uri = /** @type {T} */ (normalizeString(uri, options))
50125
50231
  } else if (typeof uri === 'object') {
50126
50232
  uri = /** @type {T} */ (parse(serialize(uri, options), options))
50127
50233
  }
@@ -50136,7 +50242,50 @@ function normalize (uri, options) {
50136
50242
  */
50137
50243
  function resolve (baseURI, relativeURI, options) {
50138
50244
  const schemelessOptions = options ? Object.assign({ scheme: 'null' }, options) : { scheme: 'null' }
50139
- const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
50245
+ const {
50246
+ parsed: baseParsed,
50247
+ malformedAuthorityOrPort: baseMalformed,
50248
+ malformedPercentEncoding: baseMalformedPercentEncoding,
50249
+ malformedSchemeSpecific: baseMalformedSchemeSpecific,
50250
+ malformedHost: baseMalformedHost,
50251
+ malformedScheme: baseMalformedScheme
50252
+ } = parseWithStatus(baseURI, schemelessOptions)
50253
+ const {
50254
+ parsed: relativeParsed,
50255
+ malformedAuthorityOrPort: relativeMalformed,
50256
+ malformedPercentEncoding: relativeMalformedPercentEncoding,
50257
+ malformedSchemeSpecific: relativeMalformedSchemeSpecific,
50258
+ malformedHost: relativeMalformedHost,
50259
+ malformedScheme: relativeMalformedScheme
50260
+ } = parseWithStatus(relativeURI, schemelessOptions)
50261
+ if (
50262
+ baseMalformed ||
50263
+ relativeMalformed ||
50264
+ baseMalformedPercentEncoding ||
50265
+ relativeMalformedPercentEncoding ||
50266
+ baseMalformedSchemeSpecific ||
50267
+ relativeMalformedSchemeSpecific ||
50268
+ baseMalformedHost ||
50269
+ relativeMalformedHost ||
50270
+ baseMalformedScheme ||
50271
+ relativeMalformedScheme
50272
+ ) {
50273
+ throw new Error(baseParsed.error || relativeParsed.error || 'URI is malformed.')
50274
+ }
50275
+ const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true)
50276
+ const resolvedSchemeHandler = getSchemeHandler((options && options.scheme) || resolved.scheme)
50277
+ const resolvedHost = resolved.host
50278
+ const resolvedHostIsIP = resolvedHost !== undefined && resolvedHost !== '' &&
50279
+ (isIPv4(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6)
50280
+ canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP)
50281
+ // Percent escapes in an ASCII reg-name are encoded data. The WHATWG hostname
50282
+ // parser can reject them even though fast-uri preserves them safely as RFC
50283
+ // 3986 data. A raw non-ASCII host must still fail closed if conversion fails.
50284
+ const encodedASCIIHost = resolvedHost && resolvedHost.indexOf('%') !== -1 &&
50285
+ !/\P{ASCII}/u.test(resolvedHost)
50286
+ if (resolved.error && !encodedASCIIHost) {
50287
+ throw new Error(resolved.error)
50288
+ }
50140
50289
  schemelessOptions.skipEscape = true
50141
50290
  return serialize(resolved, schemelessOptions)
50142
50291
  }
@@ -50216,21 +50365,10 @@ function resolveComponent (base, relative, options, skipNormalization) {
50216
50365
  * @returns {boolean}
50217
50366
  */
50218
50367
  function equal (uriA, uriB, options) {
50219
- if (typeof uriA === 'string') {
50220
- uriA = unescape(uriA)
50221
- uriA = serialize(normalizeComponentEncoding(parse(uriA, options), true), { ...options, skipEscape: true })
50222
- } else if (typeof uriA === 'object') {
50223
- uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true })
50224
- }
50368
+ const normalizedA = normalizeComparableURI(uriA, options)
50369
+ const normalizedB = normalizeComparableURI(uriB, options)
50225
50370
 
50226
- if (typeof uriB === 'string') {
50227
- uriB = unescape(uriB)
50228
- uriB = serialize(normalizeComponentEncoding(parse(uriB, options), true), { ...options, skipEscape: true })
50229
- } else if (typeof uriB === 'object') {
50230
- uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true })
50231
- }
50232
-
50233
- return uriA.toLowerCase() === uriB.toLowerCase()
50371
+ return normalizedA !== undefined && normalizedB !== undefined && normalizedA === normalizedB
50234
50372
  }
50235
50373
 
50236
50374
  /**
@@ -50258,25 +50396,30 @@ function serialize (cmpts, opts) {
50258
50396
  const options = Object.assign({}, opts)
50259
50397
  const uriTokens = []
50260
50398
 
50399
+ if (component.scheme) {
50400
+ component.scheme = decodeValidScheme(component.scheme)
50401
+ }
50402
+
50261
50403
  // find scheme handler
50262
50404
  const schemeHandler = getSchemeHandler(options.scheme || component.scheme)
50263
50405
 
50264
50406
  // perform scheme specific serialization
50265
50407
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options)
50266
50408
 
50409
+ const hasAuthority = component.userinfo !== undefined || component.host !== undefined || component.port !== undefined
50410
+ const pathNoScheme = !options.skipEscape && component.scheme === undefined && !hasAuthority
50411
+
50267
50412
  if (component.path !== undefined) {
50268
50413
  if (!options.skipEscape) {
50269
- component.path = escape(component.path)
50270
-
50271
- if (component.scheme !== undefined) {
50272
- component.path = component.path.split('%3A').join(':')
50273
- }
50414
+ component.path = serializePathEncoding(component.path, pathNoScheme)
50274
50415
  } else {
50275
- component.path = unescape(component.path)
50416
+ component.path = normalizePercentEncoding(component.path)
50276
50417
  }
50277
50418
  }
50278
50419
 
50279
50420
  if (options.reference !== 'suffix' && component.scheme) {
50421
+ // Scheme handlers may replace the scheme during serialization.
50422
+ component.scheme = decodeValidScheme(component.scheme)
50280
50423
  uriTokens.push(component.scheme, ':')
50281
50424
  }
50282
50425
 
@@ -50299,6 +50442,13 @@ function serialize (cmpts, opts) {
50299
50442
  s = removeDotSegments(s)
50300
50443
  }
50301
50444
 
50445
+ // Dot-segment removal can expose a colon that was not originally in the
50446
+ // first segment (for example, "./a:b"). Reapply path-noscheme encoding so
50447
+ // the serialized relative reference cannot be reparsed as a URI scheme.
50448
+ if (pathNoScheme) {
50449
+ s = serializePathEncoding(s, true)
50450
+ }
50451
+
50302
50452
  if (
50303
50453
  authority === undefined &&
50304
50454
  s[0] === '/' &&
@@ -50312,23 +50462,117 @@ function serialize (cmpts, opts) {
50312
50462
  }
50313
50463
 
50314
50464
  if (component.query !== undefined) {
50315
- uriTokens.push('?', component.query)
50465
+ uriTokens.push('?', encodeQuery(component.query))
50316
50466
  }
50317
50467
 
50318
50468
  if (component.fragment !== undefined) {
50319
- uriTokens.push('#', component.fragment)
50469
+ uriTokens.push('#', encodeFragment(component.fragment))
50320
50470
  }
50321
50471
  return uriTokens.join('')
50322
50472
  }
50323
50473
 
50324
50474
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u
50325
50475
 
50476
+ // Captures the authority component (between "//" and the next "/", "?" or "#"),
50477
+ // with or without a scheme prefix, for the literal-backslash rejection below.
50478
+ const AUTHORITY_PREFIX = /^(?:[^#/:?]+:)?\/\/([^/?#]*)/
50479
+
50480
+ // Captures the leading authority-introducer region after an optional scheme: a
50481
+ // run of forward slashes, backslashes, and the characters the WHATWG URL parser
50482
+ // removes before parsing (TAB U+0009, LF U+000A, CR U+000D). A valid introducer
50483
+ // is exactly "//". Node treats "\" as "/" on special schemes and strips those
50484
+ // characters first, so forms like "\\", "/\", "\/", "/<TAB>/", or a leading
50485
+ // "<TAB>//" reach an authority in Node while fast-uri's URI_PARSE folds them into
50486
+ // the path group (host confusion / SSRF / redirect bypass).
50487
+ const AUTHORITY_INTRODUCER_REGION = /^(?:[^#/:?]+:)?([/\\\t\n\r]*)/
50488
+
50489
+ /**
50490
+ * @param {import('./types/index').URIComponent} parsed
50491
+ * @param {RegExpMatchArray} matches
50492
+ * @returns {string|undefined}
50493
+ */
50494
+ function getParseError (parsed, matches) {
50495
+ if (matches[2] !== undefined && parsed.path && parsed.path[0] !== '/') {
50496
+ return 'URI path must start with "/" when authority is present.'
50497
+ }
50498
+
50499
+ if (typeof parsed.port === 'number' && (parsed.port < 0 || parsed.port > 65535)) {
50500
+ return 'URI port is malformed.'
50501
+ }
50502
+
50503
+ return undefined
50504
+ }
50505
+
50506
+ /**
50507
+ * Checks percent syntax without decoding the represented octets. RFC 3986
50508
+ * percent-encoding is byte-oriented, so sequences such as `%FF` are valid even
50509
+ * though they are not independently valid UTF-8.
50510
+ *
50511
+ * @param {string|undefined} component
50512
+ * @returns {boolean}
50513
+ */
50514
+ function hasMalformedPercentEncoding (component) {
50515
+ if (component === undefined) return false
50516
+
50517
+ let percent = component.indexOf('%')
50518
+ while (percent !== -1) {
50519
+ if (percent + 2 >= component.length || !/^[\da-f]{2}$/iu.test(component.slice(percent + 1, percent + 3))) {
50520
+ return true
50521
+ }
50522
+ percent = component.indexOf('%', percent + 3)
50523
+ }
50524
+
50525
+ return false
50526
+ }
50527
+
50528
+ /**
50529
+ * @param {RegExpMatchArray} matches
50530
+ * @returns {boolean}
50531
+ */
50532
+ function hasMalformedComponentPercentEncoding (matches) {
50533
+ // Bracketed IP literals use a raw "%" as the zone separator for historical
50534
+ // compatibility. Their parsing is intentionally left to normalizeIPv6.
50535
+ const host = matches[4]
50536
+ return hasMalformedPercentEncoding(matches[3]) ||
50537
+ (host !== undefined && !(host[0] === '[' && host[host.length - 1] === ']') && hasMalformedPercentEncoding(host)) ||
50538
+ hasMalformedPercentEncoding(matches[6]) ||
50539
+ hasMalformedPercentEncoding(matches[7]) ||
50540
+ hasMalformedPercentEncoding(matches[8])
50541
+ }
50542
+
50543
+ /**
50544
+ * @param {import('./types/index').URIComponent} parsed
50545
+ * @param {import('./types/index').Options} options
50546
+ * @param {{ domainHost?: boolean, unicodeSupport?: boolean }|undefined} schemeHandler
50547
+ * @param {boolean} isIP
50548
+ * @returns {boolean} whether host conversion failed
50549
+ */
50550
+ function canonicalizeHost (parsed, options, schemeHandler, isIP) {
50551
+ if (
50552
+ !options.unicodeSupport &&
50553
+ (!schemeHandler || !schemeHandler.unicodeSupport) &&
50554
+ parsed.host &&
50555
+ parsed.host[0] !== '[' &&
50556
+ (options.domainHost || (schemeHandler && schemeHandler.domainHost)) &&
50557
+ isIP === false &&
50558
+ nonSimpleDomain(parsed.host)
50559
+ ) {
50560
+ try {
50561
+ parsed.host = new URL('http://' + parsed.host).hostname
50562
+ } catch (e) {
50563
+ parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
50564
+ return true
50565
+ }
50566
+ }
50567
+ return false
50568
+ }
50569
+
50326
50570
  /**
50327
50571
  * @param {string} uri
50328
50572
  * @param {import('./types/index').Options} [opts]
50329
- * @returns
50573
+ * @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean, malformedPercentEncoding: boolean, malformedSchemeSpecific: boolean, malformedHost: boolean, malformedScheme: boolean }}
50330
50574
  */
50331
- function parse (uri, opts) {
50575
+ function parseWithStatus (uri, opts) {
50332
50576
  const options = Object.assign({}, opts)
50333
50577
  /** @type {import('./types/index').URIComponent} */
50334
50578
  const parsed = {
@@ -50341,6 +50585,13 @@ function parse (uri, opts) {
50341
50585
  fragment: undefined
50342
50586
  }
50343
50587
 
50588
+ let malformedAuthorityOrPort = false
50589
+ let malformedPercentEncoding = false
50590
+ let malformedSchemeSpecific = false
50591
+ let malformedHost = false
50592
+ let malformedIPLiteral = false
50593
+ let malformedScheme = false
50594
+
50344
50595
  let isIP = false
50345
50596
  if (options.reference === 'suffix') {
50346
50597
  if (options.scheme) {
@@ -50350,6 +50601,41 @@ function parse (uri, opts) {
50350
50601
  }
50351
50602
  }
50352
50603
 
50604
+ // A literal backslash (U+005C) is not a valid RFC 3986 URI character and is
50605
+ // not an authority delimiter. Reject it in the authority rather than
50606
+ // rewriting it: normalizing "\" -> "/" (WHATWG error recovery) could silently
50607
+ // change the resource identified by an otherwise-invalid input, and lets "\"
50608
+ // act as a host delimiter here while Node's native URL parses a different
50609
+ // host (SSRF / redirect / origin-allowlist bypass). Percent-encoded %5C is
50610
+ // untouched and remains valid encoded data.
50611
+ const authorityMatch = uri.match(AUTHORITY_PREFIX)
50612
+ if (authorityMatch !== null && authorityMatch[1].indexOf('\\') !== -1) {
50613
+ parsed.error = 'URI authority must not contain a literal backslash.'
50614
+ malformedAuthorityOrPort = true
50615
+ }
50616
+
50617
+ // Reject a malformed or whitespace-smuggled authority introducer. fast-uri
50618
+ // only recognizes a literal "//"; anything else in the leading separator run
50619
+ // (a backslash, or a "//" that appears only after removing the TAB/LF/CR that
50620
+ // Node strips) means the authority fast-uri parses differs from the one Node's
50621
+ // URL resolves. Reject rather than rewrite, mirroring the literal-backslash
50622
+ // guard above. Percent-encoded forms (%5C, %09) are untouched, valid data.
50623
+ const introducerMatch = uri.match(AUTHORITY_INTRODUCER_REGION)
50624
+ if (introducerMatch !== null) {
50625
+ const region = introducerMatch[1]
50626
+ const normalizedRegion = region.replace(/[\t\n\r]/g, '')
50627
+ // Two or more leading separators introduce an authority.
50628
+ if (normalizedRegion.length >= 2) {
50629
+ if (normalizedRegion.slice(0, 2) !== '//') {
50630
+ parsed.error = parsed.error || 'URI authority must not contain a literal backslash.'
50631
+ malformedAuthorityOrPort = true
50632
+ } else if (region.length !== normalizedRegion.length) {
50633
+ parsed.error = parsed.error || 'URI authority introducer must not contain whitespace.'
50634
+ malformedAuthorityOrPort = true
50635
+ }
50636
+ }
50637
+ }
50638
+
50353
50639
  const matches = uri.match(URI_PARSE)
50354
50640
 
50355
50641
  if (matches) {
@@ -50362,16 +50648,45 @@ function parse (uri, opts) {
50362
50648
  parsed.query = matches[7]
50363
50649
  parsed.fragment = matches[8]
50364
50650
 
50651
+ if (parsed.scheme !== undefined) {
50652
+ const decodedScheme = unescape(parsed.scheme)
50653
+ if (VALID_SCHEME.test(decodedScheme)) {
50654
+ parsed.scheme = decodedScheme.toLowerCase()
50655
+ } else {
50656
+ parsed.error = parsed.error || MALFORMED_SCHEME_ERROR
50657
+ malformedScheme = true
50658
+ }
50659
+ }
50660
+
50661
+ malformedPercentEncoding = hasMalformedComponentPercentEncoding(matches)
50662
+ if (malformedPercentEncoding) {
50663
+ parsed.error = parsed.error || 'URI contains malformed percent-encoding.'
50664
+ }
50665
+
50365
50666
  // fix port number
50366
50667
  if (isNaN(parsed.port)) {
50367
50668
  parsed.port = matches[5]
50368
50669
  }
50670
+
50671
+ const parseError = getParseError(parsed, matches)
50672
+ if (parseError !== undefined) {
50673
+ parsed.error = parsed.error || parseError
50674
+ malformedAuthorityOrPort = true
50675
+ }
50676
+
50369
50677
  if (parsed.host) {
50370
50678
  const ipv4result = isIPv4(parsed.host)
50371
50679
  if (ipv4result === false) {
50680
+ const bracketedIPLiteral = parsed.host[0] === '[' && parsed.host[parsed.host.length - 1] === ']'
50372
50681
  const ipv6result = normalizeIPv6(parsed.host)
50373
- parsed.host = ipv6result.host.toLowerCase()
50374
- isIP = ipv6result.isIPV6
50682
+ isIP = ipv6result.isIPV6 || ipv6result.isIPVFuture === true
50683
+ malformedIPLiteral = bracketedIPLiteral && ipv6result.error === true
50684
+ parsed.host = isIP ? ipv6result.host : ipv6result.host.toLowerCase()
50685
+
50686
+ if (malformedIPLiteral) {
50687
+ parsed.error = parsed.error || 'URI host is malformed.'
50688
+ malformedAuthorityOrPort = true
50689
+ }
50375
50690
  } else {
50376
50691
  isIP = true
50377
50692
  }
@@ -50394,45 +50709,93 @@ function parse (uri, opts) {
50394
50709
  // find scheme handler
50395
50710
  const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme)
50396
50711
 
50397
- // check if scheme can't handle IRIs
50398
- if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
50399
- // if host component is a domain name
50400
- if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {
50401
- // convert Unicode IDN -> ASCII IDN
50402
- try {
50403
- parsed.host = URL.domainToASCII(parsed.host.toLowerCase())
50404
- } catch (e) {
50405
- parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
50406
- }
50407
- }
50408
- // convert IRI -> URI
50409
- }
50712
+ // convert Unicode IDN -> ASCII IDN when the effective scheme uses domain hosts
50713
+ malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP)
50410
50714
 
50411
50715
  if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
50412
50716
  if (uri.indexOf('%') !== -1) {
50413
- if (parsed.scheme !== undefined) {
50414
- parsed.scheme = unescape(parsed.scheme)
50415
- }
50416
- if (parsed.host !== undefined) {
50417
- parsed.host = unescape(parsed.host)
50717
+ if (parsed.host !== undefined && !malformedIPLiteral) {
50718
+ const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true)
50719
+ parsed.host = reescapeHostDelimiters(host, isIP)
50418
50720
  }
50419
50721
  }
50420
50722
  if (parsed.path) {
50421
- parsed.path = escape(unescape(parsed.path))
50723
+ parsed.path = normalizePathEncoding(parsed.path)
50724
+ }
50725
+ if (parsed.query) {
50726
+ parsed.query = normalizeQueryFragmentEncoding(parsed.query)
50422
50727
  }
50423
50728
  if (parsed.fragment) {
50424
- parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment))
50729
+ parsed.fragment = normalizeQueryFragmentEncoding(parsed.fragment)
50425
50730
  }
50426
50731
  }
50427
50732
 
50428
50733
  // perform scheme specific parsing
50429
50734
  if (schemeHandler && schemeHandler.parse) {
50430
50735
  schemeHandler.parse(parsed, options)
50736
+ if (schemeHandler === SCHEMES.urn && parsed.nid === undefined) {
50737
+ malformedSchemeSpecific = true
50738
+ }
50431
50739
  }
50432
50740
  } else {
50433
50741
  parsed.error = parsed.error || 'URI can not be parsed.'
50434
50742
  }
50435
- return parsed
50743
+ return { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme }
50744
+ }
50745
+
50746
+ /**
50747
+ * @param {string} uri
50748
+ * @param {import('./types/index').Options} [opts]
50749
+ * @returns
50750
+ */
50751
+ function parse (uri, opts) {
50752
+ return parseWithStatus(uri, opts).parsed
50753
+ }
50754
+
50755
+ /**
50756
+ * @param {string} uri
50757
+ * @param {import('./types/index').Options} [opts]
50758
+ * @returns {string}
50759
+ */
50760
+ function normalizeString (uri, opts) {
50761
+ return normalizeStringWithStatus(uri, opts).normalized
50762
+ }
50763
+
50764
+ /**
50765
+ * @param {string} uri
50766
+ * @param {import('./types/index').Options} [opts]
50767
+ * @returns {{ normalized: string, malformedAuthorityOrPort: boolean, malformedPercentEncoding: boolean, malformedSchemeSpecific: boolean, malformedHost: boolean, malformedScheme: boolean }}
50768
+ */
50769
+ function normalizeStringWithStatus (uri, opts) {
50770
+ const { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = parseWithStatus(uri, opts)
50771
+ return {
50772
+ normalized: malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? uri : serialize(parsed, opts),
50773
+ malformedAuthorityOrPort,
50774
+ malformedPercentEncoding,
50775
+ malformedSchemeSpecific,
50776
+ malformedHost,
50777
+ malformedScheme
50778
+ }
50779
+ }
50780
+
50781
+ /**
50782
+ * @param {import ('./types/index').URIComponent|string} uri
50783
+ * @param {import('./types/index').Options} [opts]
50784
+ * @returns {string|undefined}
50785
+ */
50786
+ function normalizeComparableURI (uri, opts) {
50787
+ if (typeof uri !== 'string' && typeof uri !== 'object') {
50788
+ return undefined
50789
+ }
50790
+
50791
+ let value
50792
+ try {
50793
+ value = typeof uri === 'string' ? uri : serialize(uri, opts)
50794
+ } catch {
50795
+ return undefined
50796
+ }
50797
+ const { normalized, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = normalizeStringWithStatus(value, opts)
50798
+ return malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? undefined : normalized
50436
50799
  }
50437
50800
 
50438
50801
  const fastUri = {
@@ -50459,7 +50822,7 @@ module.exports.fastUri = fastUri
50459
50822
 
50460
50823
 
50461
50824
  const { isUUID } = __nccwpck_require__(5077)
50462
- const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu
50825
+ const URN_REG = /^([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-./:;=@]|%[\da-f]{2})+)$/iu
50463
50826
 
50464
50827
  const supportedSchemeNames = /** @type {const} */ (['http', 'https', 'ws',
50465
50828
  'wss', 'urn', 'urn:uuid'])
@@ -50571,9 +50934,14 @@ function wsSerialize (wsComponent) {
50571
50934
 
50572
50935
  // reconstruct path from resource name
50573
50936
  if (wsComponent.resourceName) {
50574
- const [path, query] = wsComponent.resourceName.split('?')
50937
+ const queryIndex = wsComponent.resourceName.indexOf('?')
50938
+ const path = queryIndex === -1
50939
+ ? wsComponent.resourceName
50940
+ : wsComponent.resourceName.slice(0, queryIndex)
50575
50941
  wsComponent.path = (path && path !== '/' ? path : undefined)
50576
- wsComponent.query = query
50942
+ wsComponent.query = queryIndex === -1
50943
+ ? undefined
50944
+ : wsComponent.resourceName.slice(queryIndex + 1)
50577
50945
  wsComponent.resourceName = undefined
50578
50946
  }
50579
50947
 
@@ -50590,7 +50958,7 @@ function urnParse (urnComponent, options) {
50590
50958
  return urnComponent
50591
50959
  }
50592
50960
  const matches = urnComponent.path.match(URN_REG)
50593
- if (matches) {
50961
+ if (matches && matches[0] === urnComponent.path) {
50594
50962
  const scheme = options.scheme || urnComponent.scheme || 'urn'
50595
50963
  urnComponent.nid = matches[1].toLowerCase()
50596
50964
  urnComponent.nss = matches[2]
@@ -50739,6 +51107,44 @@ const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\d
50739
51107
  /** @type {(value: string) => boolean} */
50740
51108
  const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u)
50741
51109
 
51110
+ /** @type {(value: string) => boolean} */
51111
+ const isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu)
51112
+
51113
+ /** @type {(value: string) => boolean} */
51114
+ const isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu)
51115
+
51116
+ /** @type {(value: string) => boolean} */
51117
+ const isPathCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/]$/u)
51118
+
51119
+ /** @type {(value: string) => boolean} */
51120
+ const isQueryFragmentCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/?]$/u)
51121
+
51122
+ /** @type {(value: string) => boolean} */
51123
+ const isUserinfoCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:]$/u)
51124
+
51125
+ const BYTE_HEX = new Array(256)
51126
+ {
51127
+ const HEX_DIGITS = '0123456789ABCDEF'
51128
+ for (let i = 0; i < 256; i++) {
51129
+ BYTE_HEX[i] = '%' + HEX_DIGITS[i >> 4] + HEX_DIGITS[i & 0xF]
51130
+ }
51131
+ }
51132
+ function percentEncodeNonAscii (cp) {
51133
+ if (cp < 0x800) {
51134
+ return BYTE_HEX[0xC0 | (cp >> 6)] +
51135
+ BYTE_HEX[0x80 | (cp & 0x3F)]
51136
+ }
51137
+ if (cp < 0x10000) {
51138
+ return BYTE_HEX[0xE0 | (cp >> 12)] +
51139
+ BYTE_HEX[0x80 | ((cp >> 6) & 0x3F)] +
51140
+ BYTE_HEX[0x80 | (cp & 0x3F)]
51141
+ }
51142
+ return BYTE_HEX[0xF0 | (cp >> 18)] +
51143
+ BYTE_HEX[0x80 | ((cp >> 12) & 0x3F)] +
51144
+ BYTE_HEX[0x80 | ((cp >> 6) & 0x3F)] +
51145
+ BYTE_HEX[0x80 | (cp & 0x3F)]
51146
+ }
51147
+
50742
51148
  /**
50743
51149
  * @param {Array<string>} input
50744
51150
  * @returns {string}
@@ -50770,12 +51176,14 @@ function stringArrayToHexStripped (input) {
50770
51176
  return acc
50771
51177
  }
50772
51178
 
50773
- /**
50774
- * @typedef {Object} GetIPV6Result
50775
- * @property {boolean} error - Indicates if there was an error parsing the IPv6 address.
50776
- * @property {string} address - The parsed IPv6 address.
50777
- * @property {string} [zone] - The zone identifier, if present.
50778
- */
51179
+ /** @type {(value: string) => boolean} */
51180
+ const isHextet = RegExp.prototype.test.bind(/^[\dA-Fa-f]{1,4}$/)
51181
+
51182
+ /** @type {(value: string) => boolean} */
51183
+ const isIPvFuture = RegExp.prototype.test.bind(/^[vV][\dA-Fa-f]+\.[A-Za-z\d\-._~!$&'()*+,;=:]+$/)
51184
+
51185
+ /** @type {(value: string) => boolean} */
51186
+ const isZoneCharacter = RegExp.prototype.test.bind(/^[A-Za-z\d\-._~]$/)
50779
51187
 
50780
51188
  /**
50781
51189
  * @param {string} value
@@ -50784,88 +51192,104 @@ function stringArrayToHexStripped (input) {
50784
51192
  const nonSimpleDomain = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u)
50785
51193
 
50786
51194
  /**
50787
- * @param {Array<string>} buffer
51195
+ * @param {string} zone
50788
51196
  * @returns {boolean}
50789
51197
  */
50790
- function consumeIsZone (buffer) {
50791
- buffer.length = 0
51198
+ function isZoneIdentifier (zone) {
51199
+ if (zone.length === 0) return false
51200
+
51201
+ for (let i = 0; i < zone.length; i++) {
51202
+ if (isZoneCharacter(zone[i])) continue
51203
+ if (zone[i] === '%' && i + 2 < zone.length && isHexPair(zone.slice(i + 1, i + 3))) {
51204
+ i += 2
51205
+ continue
51206
+ }
51207
+ return false
51208
+ }
51209
+
50792
51210
  return true
50793
51211
  }
50794
51212
 
50795
51213
  /**
50796
- * @param {Array<string>} buffer
50797
- * @param {Array<string>} address
50798
- * @param {GetIPV6Result} output
50799
- * @returns {boolean}
51214
+ * Compresses the longest run of zero hextets to "::" per RFC 5952. A run of a
51215
+ * single zero hextet is left uncompressed. On ties the leftmost run wins.
51216
+ *
51217
+ * @param {string[]} hextets
51218
+ * @returns {string}
50800
51219
  */
50801
- function consumeHextets (buffer, address, output) {
50802
- if (buffer.length) {
50803
- const hex = stringArrayToHexStripped(buffer)
50804
- if (hex !== '') {
50805
- address.push(hex)
51220
+ function compressIPv6ZeroRun (hextets) {
51221
+ let bestStart = -1
51222
+ let bestLength = 0
51223
+ let runStart = -1
51224
+ let runLength = 0
51225
+ for (let i = 0; i < hextets.length; i++) {
51226
+ if (hextets[i] === '0') {
51227
+ if (runStart === -1) runStart = i
51228
+ runLength++
51229
+ if (runLength > bestLength) {
51230
+ bestLength = runLength
51231
+ bestStart = runStart
51232
+ }
50806
51233
  } else {
50807
- output.error = true
50808
- return false
51234
+ runStart = -1
51235
+ runLength = 0
50809
51236
  }
50810
- buffer.length = 0
50811
51237
  }
50812
- return true
51238
+
51239
+ if (bestLength < 2) return hextets.join(':')
51240
+
51241
+ const head = hextets.slice(0, bestStart).join(':')
51242
+ const tail = hextets.slice(bestStart + bestLength).join(':')
51243
+ return head + '::' + tail
50813
51244
  }
50814
51245
 
50815
51246
  /**
51247
+ * Validates an IPv6 address against the alternatives in RFC 3986 section
51248
+ * 3.2.2 and returns the same address with leading hextet zeroes removed.
51249
+ * An embedded IPv4 address counts as two hextets and is only valid at the end.
51250
+ *
50816
51251
  * @param {string} input
50817
- * @returns {GetIPV6Result}
51252
+ * @returns {string|undefined}
50818
51253
  */
50819
- function getIPV6 (input) {
50820
- let tokenCount = 0
50821
- const output = { error: false, address: '', zone: '' }
50822
- /** @type {Array<string>} */
50823
- const address = []
50824
- /** @type {Array<string>} */
50825
- const buffer = []
50826
- let endipv6Encountered = false
50827
- let endIpv6 = false
50828
-
50829
- let consume = consumeHextets
50830
-
50831
- for (let i = 0; i < input.length; i++) {
50832
- const cursor = input[i]
50833
- if (cursor === '[' || cursor === ']') { continue }
50834
- if (cursor === ':') {
50835
- if (endipv6Encountered === true) {
50836
- endIpv6 = true
50837
- }
50838
- if (!consume(buffer, address, output)) { break }
50839
- if (++tokenCount > 7) {
50840
- // not valid
50841
- output.error = true
50842
- break
50843
- }
50844
- if (i > 0 && input[i - 1] === ':') {
50845
- endipv6Encountered = true
50846
- }
50847
- address.push(':')
50848
- continue
50849
- } else if (cursor === '%') {
50850
- if (!consume(buffer, address, output)) { break }
50851
- // switch to zone detection
50852
- consume = consumeIsZone
50853
- } else {
50854
- buffer.push(cursor)
51254
+ function normalizeIPv6Address (input) {
51255
+ const compression = input.indexOf('::')
51256
+ if (compression !== -1 && input.indexOf('::', compression + 1) !== -1) return undefined
51257
+
51258
+ const left = compression === -1 ? input.split(':') : input.slice(0, compression).split(':')
51259
+ const right = compression === -1 ? [] : input.slice(compression + 2).split(':')
51260
+ if (compression !== -1) {
51261
+ if (left.length === 1 && left[0] === '') left.length = 0
51262
+ if (right.length === 1 && right[0] === '') right.length = 0
51263
+ }
51264
+
51265
+ const parts = left.concat(right)
51266
+ let hextetCount = 0
51267
+ for (let i = 0; i < parts.length; i++) {
51268
+ const part = parts[i]
51269
+ if (part === '') return undefined
51270
+
51271
+ if (part.indexOf('.') !== -1) {
51272
+ if (i !== parts.length - 1 || (compression !== -1 && right.length === 0) || !isIPv4(part)) return undefined
51273
+ hextetCount += 2
50855
51274
  continue
50856
51275
  }
51276
+
51277
+ if (!isHextet(part)) return undefined
51278
+ parts[i] = parseInt(part, 16).toString(16)
51279
+ hextetCount++
50857
51280
  }
50858
- if (buffer.length) {
50859
- if (consume === consumeIsZone) {
50860
- output.zone = buffer.join('')
50861
- } else if (endIpv6) {
50862
- address.push(buffer.join(''))
50863
- } else {
50864
- address.push(stringArrayToHexStripped(buffer))
50865
- }
51281
+
51282
+ if (compression === -1) {
51283
+ if (hextetCount !== 8) return undefined
51284
+ return compressIPv6ZeroRun(parts)
50866
51285
  }
50867
- output.address = address.join('')
50868
- return output
51286
+ if (hextetCount >= 8) return undefined
51287
+
51288
+ // expand "::" then re-compress the longest run for a canonical result
51289
+ const expanded = parts.slice(0, left.length)
51290
+ for (let i = hextetCount; i < 8; i++) expanded.push('0')
51291
+ for (let i = left.length; i < parts.length; i++) expanded.push(parts[i])
51292
+ return compressIPv6ZeroRun(expanded)
50869
51293
  }
50870
51294
 
50871
51295
  /**
@@ -50873,26 +51297,49 @@ function getIPV6 (input) {
50873
51297
  * @property {string} host - The normalized host.
50874
51298
  * @property {string} [escapedHost] - The escaped host.
50875
51299
  * @property {boolean} isIPV6 - Indicates if the host is an IPv6 address.
51300
+ * @property {boolean} [isIPVFuture] - Indicates if the host is an IPvFuture literal.
51301
+ * @property {boolean} [error] - Indicates if a bracketed IP literal is malformed.
50876
51302
  */
50877
51303
 
50878
51304
  /**
51305
+ * Validates and normalizes a bracketed IP literal. Raw zone separators remain
51306
+ * accepted for backwards compatibility, while encoded separators and zone
51307
+ * contents follow RFC 6874.
51308
+ *
50879
51309
  * @param {string} host
50880
51310
  * @returns {NormalizeIPv6Result}
50881
51311
  */
50882
51312
  function normalizeIPv6 (host) {
50883
- if (findToken(host, ':') < 2) { return { host, isIPV6: false } }
50884
- const ipv6 = getIPV6(host)
51313
+ const bracketed = host[0] === '[' && host[host.length - 1] === ']'
51314
+ const hasBracket = host[0] === '[' || host[host.length - 1] === ']'
51315
+ if (hasBracket && !bracketed) return { host, isIPV6: false, error: true }
50885
51316
 
50886
- if (!ipv6.error) {
50887
- let newHost = ipv6.address
50888
- let escapedHost = ipv6.address
50889
- if (ipv6.zone) {
50890
- newHost += '%' + ipv6.zone
50891
- escapedHost += '%25' + ipv6.zone
50892
- }
50893
- return { host: newHost, isIPV6: true, escapedHost }
50894
- } else {
50895
- return { host, isIPV6: false }
51317
+ let input = bracketed ? host.slice(1, -1) : host
51318
+ if (bracketed && isIPvFuture(input)) {
51319
+ input = input.toLowerCase()
51320
+ return { host: `[${input}]`, escapedHost: input, isIPV6: false, isIPVFuture: true }
51321
+ }
51322
+
51323
+ if (findToken(input, ':') < 2) {
51324
+ return { host, isIPV6: false, error: bracketed }
51325
+ }
51326
+
51327
+ let zoneIdentifier = ''
51328
+ const zoneSeparator = input.indexOf('%')
51329
+ if (zoneSeparator !== -1) {
51330
+ const separatorLength = input.slice(zoneSeparator, zoneSeparator + 3).toLowerCase() === '%25' ? 3 : 1
51331
+ zoneIdentifier = input.slice(zoneSeparator + separatorLength)
51332
+ if (!isZoneIdentifier(zoneIdentifier)) return { host, isIPV6: false, error: true }
51333
+ input = input.slice(0, zoneSeparator)
51334
+ }
51335
+
51336
+ const address = normalizeIPv6Address(input)
51337
+ if (address === undefined) return { host, isIPV6: false, error: true }
51338
+
51339
+ return {
51340
+ host: address + (zoneIdentifier ? '%' + zoneIdentifier : ''),
51341
+ escapedHost: address + (zoneIdentifier ? '%25' + zoneIdentifier : ''),
51342
+ isIPV6: true
50896
51343
  }
50897
51344
  }
50898
51345
 
@@ -50997,31 +51444,342 @@ function removeDotSegments (path) {
50997
51444
  }
50998
51445
 
50999
51446
  /**
51000
- * @param {import('../types/index').URIComponent} component
51001
- * @param {boolean} esc
51002
- * @returns {import('../types/index').URIComponent}
51447
+ * Re-escape RFC 3986 gen-delims that must not appear literally in the host.
51448
+ * After the URI regex parses, these characters cannot be literal in the host
51449
+ * field, so any that appear after decoding came from percent-encoding and
51450
+ * must be restored to prevent authority structure changes.
51451
+ *
51452
+ * @param {string} host
51453
+ * @param {boolean} isIP - true for IPv4/IPv6 hosts (skip colon re-escaping)
51454
+ * @returns {string}
51455
+ */
51456
+ const HOST_DELIMS = { '@': '%40', '/': '%2F', '?': '%3F', '#': '%23', ':': '%3A' }
51457
+ const HOST_DELIM_RE = /[@/?#:]/g
51458
+ const HOST_DELIM_NO_COLON_RE = /[@/?#]/g
51459
+
51460
+ function reescapeHostDelimiters (host, isIP) {
51461
+ const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE
51462
+ re.lastIndex = 0
51463
+ return host.replace(re, (ch) => HOST_DELIMS[ch])
51464
+ }
51465
+
51466
+ /**
51467
+ * Normalizes percent escapes and optionally decodes only unreserved ASCII bytes.
51468
+ * Reserved delimiters such as `%2F` stay escaped; `%2E` is unreserved.
51469
+ *
51470
+ * @param {string} input
51471
+ * @param {boolean} [decodeUnreserved=false]
51472
+ * @returns {string}
51003
51473
  */
51004
- function normalizeComponentEncoding (component, esc) {
51005
- const func = esc !== true ? escape : unescape
51006
- if (component.scheme !== undefined) {
51007
- component.scheme = func(component.scheme)
51474
+ function normalizePercentEncoding (input, decodeUnreserved = false) {
51475
+ if (input.indexOf('%') === -1) {
51476
+ return input
51008
51477
  }
51009
- if (component.userinfo !== undefined) {
51010
- component.userinfo = func(component.userinfo)
51478
+
51479
+ let output = ''
51480
+
51481
+ for (let i = 0; i < input.length; i++) {
51482
+ if (input[i] === '%' && i + 2 < input.length) {
51483
+ const hex = input.slice(i + 1, i + 3)
51484
+ if (isHexPair(hex)) {
51485
+ const normalizedHex = hex.toUpperCase()
51486
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16))
51487
+
51488
+ if (decodeUnreserved && isUnreserved(decoded)) {
51489
+ output += decoded
51490
+ } else {
51491
+ output += '%' + normalizedHex
51492
+ }
51493
+
51494
+ i += 2
51495
+ continue
51496
+ }
51497
+ }
51498
+
51499
+ output += input[i]
51011
51500
  }
51012
- if (component.host !== undefined) {
51013
- component.host = func(component.host)
51501
+
51502
+ return output
51503
+ }
51504
+
51505
+ /**
51506
+ * Normalizes path data without turning reserved escapes into live path syntax.
51507
+ * Valid escapes are uppercased, raw unsafe characters are escaped, and only
51508
+ * unreserved bytes that are not `.` are decoded.
51509
+ *
51510
+ * @param {string} input
51511
+ * @returns {string}
51512
+ */
51513
+ function normalizePathEncoding (input) {
51514
+ let output = ''
51515
+
51516
+ for (let i = 0; i < input.length; i++) {
51517
+ const ch = input[i]
51518
+ if (ch === '%' && i + 2 < input.length) {
51519
+ const hex = input.slice(i + 1, i + 3)
51520
+ if (isHexPair(hex)) {
51521
+ const normalizedHex = hex.toUpperCase()
51522
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16))
51523
+
51524
+ if (decoded !== '.' && isUnreserved(decoded)) {
51525
+ output += decoded
51526
+ } else {
51527
+ output += '%' + normalizedHex
51528
+ }
51529
+
51530
+ i += 2
51531
+ continue
51532
+ }
51533
+ }
51534
+
51535
+ if (isPathCharacter(ch)) {
51536
+ output += ch
51537
+ } else {
51538
+ const code = input.charCodeAt(i)
51539
+ if (code < 0x80) {
51540
+ output += isEscapeSafe(code) ? ch : BYTE_HEX[code]
51541
+ } else if (code < 0xD800 || code > 0xDFFF) {
51542
+ output += percentEncodeNonAscii(code)
51543
+ } else if (code <= 0xDBFF && i + 1 < input.length) {
51544
+ const low = input.charCodeAt(i + 1)
51545
+ if (low >= 0xDC00 && low <= 0xDFFF) {
51546
+ output += percentEncodeNonAscii(0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00))
51547
+ i++
51548
+ } else {
51549
+ output += percentEncodeNonAscii(0xFFFD)
51550
+ }
51551
+ } else {
51552
+ output += percentEncodeNonAscii(0xFFFD)
51553
+ }
51554
+ }
51014
51555
  }
51015
- if (component.path !== undefined) {
51016
- component.path = func(component.path)
51556
+
51557
+ return output
51558
+ }
51559
+
51560
+ /**
51561
+ * Serializes a path without rewriting reserved data. Raw RFC 3986 path
51562
+ * characters remain literal, valid escapes are preserved and uppercased, and
51563
+ * everything else is UTF-8 percent-encoded. In a path-noscheme, a colon in the
51564
+ * first segment must be escaped so the result cannot be parsed as a scheme.
51565
+ *
51566
+ * @param {string} input
51567
+ * @param {boolean} [pathNoScheme=false]
51568
+ * @returns {string}
51569
+ */
51570
+ function serializePathEncoding (input, pathNoScheme = false) {
51571
+ let output = ''
51572
+ let firstSegment = pathNoScheme && input[0] !== '/'
51573
+
51574
+ for (let i = 0; i < input.length; i++) {
51575
+ const ch = input[i]
51576
+ if (ch === '%' && i + 2 < input.length) {
51577
+ const hex = input.slice(i + 1, i + 3)
51578
+ if (isHexPair(hex)) {
51579
+ output += '%' + hex.toUpperCase()
51580
+ i += 2
51581
+ continue
51582
+ }
51583
+ }
51584
+
51585
+ if (ch === '/') {
51586
+ firstSegment = false
51587
+ }
51588
+
51589
+ if (isPathCharacter(ch) && (ch !== ':' || !firstSegment)) {
51590
+ output += ch
51591
+ } else {
51592
+ const code = input.charCodeAt(i)
51593
+ if (code < 0x80) {
51594
+ output += BYTE_HEX[code]
51595
+ } else if (code < 0xD800 || code > 0xDFFF) {
51596
+ output += percentEncodeNonAscii(code)
51597
+ } else if (code <= 0xDBFF && i + 1 < input.length) {
51598
+ const low = input.charCodeAt(i + 1)
51599
+ if (low >= 0xDC00 && low <= 0xDFFF) {
51600
+ output += percentEncodeNonAscii(0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00))
51601
+ i++
51602
+ } else {
51603
+ output += percentEncodeNonAscii(0xFFFD)
51604
+ }
51605
+ } else {
51606
+ output += percentEncodeNonAscii(0xFFFD)
51607
+ }
51608
+ }
51017
51609
  }
51018
- if (component.query !== undefined) {
51019
- component.query = func(component.query)
51610
+
51611
+ return output
51612
+ }
51613
+
51614
+ /**
51615
+ * Percent-encodes a URI component using its RFC 3986 literal character set.
51616
+ * Existing valid escapes are preserved and normalized to uppercase hex.
51617
+ *
51618
+ * @param {string} input
51619
+ * @param {(value: string) => boolean} isAllowed
51620
+ * @returns {string}
51621
+ */
51622
+ function encodeComponent (input, isAllowed) {
51623
+ let output = ''
51624
+
51625
+ for (let i = 0; i < input.length; i++) {
51626
+ const ch = input[i]
51627
+ if (ch === '%' && i + 2 < input.length) {
51628
+ const hex = input.slice(i + 1, i + 3)
51629
+ if (isHexPair(hex)) {
51630
+ output += '%' + hex.toUpperCase()
51631
+ i += 2
51632
+ continue
51633
+ }
51634
+ }
51635
+
51636
+ if (isAllowed(ch)) {
51637
+ output += ch
51638
+ } else {
51639
+ const code = input.charCodeAt(i)
51640
+ if (code < 0x80) {
51641
+ output += BYTE_HEX[code]
51642
+ } else if (code < 0xD800 || code > 0xDFFF) {
51643
+ output += percentEncodeNonAscii(code)
51644
+ } else if (code <= 0xDBFF && i + 1 < input.length) {
51645
+ const low = input.charCodeAt(i + 1)
51646
+ if (low >= 0xDC00 && low <= 0xDFFF) {
51647
+ output += percentEncodeNonAscii(0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00))
51648
+ i++
51649
+ } else {
51650
+ output += percentEncodeNonAscii(0xFFFD)
51651
+ }
51652
+ } else {
51653
+ output += percentEncodeNonAscii(0xFFFD)
51654
+ }
51655
+ }
51020
51656
  }
51021
- if (component.fragment !== undefined) {
51022
- component.fragment = func(component.fragment)
51657
+
51658
+ return output
51659
+ }
51660
+
51661
+ /**
51662
+ * Encodes userinfo while preserving its RFC 3986 §3.2.1 literal characters.
51663
+ * In particular, authority delimiters such as `@`, `/`, `?`, and `#` are data.
51664
+ *
51665
+ * @param {string} input
51666
+ * @returns {string}
51667
+ */
51668
+ function encodeUserinfo (input) {
51669
+ return encodeComponent(input, isUserinfoCharacter)
51670
+ }
51671
+
51672
+ /**
51673
+ * Encodes query data using the RFC 3986 §3.4 grammar. A literal `#` must be
51674
+ * escaped because it would otherwise begin the fragment component.
51675
+ *
51676
+ * @param {string} input
51677
+ * @returns {string}
51678
+ */
51679
+ function encodeQuery (input) {
51680
+ return encodeComponent(input, isQueryFragmentCharacter)
51681
+ }
51682
+
51683
+ /**
51684
+ * Encodes fragment data using the RFC 3986 §3.5 grammar.
51685
+ *
51686
+ * @param {string} input
51687
+ * @returns {string}
51688
+ */
51689
+ function encodeFragment (input) {
51690
+ return encodeComponent(input, isQueryFragmentCharacter)
51691
+ }
51692
+
51693
+ function isEscapeSafe (cp) {
51694
+ return (
51695
+ (cp >= 0x30 && cp <= 0x39) ||
51696
+ (cp >= 0x41 && cp <= 0x5A) ||
51697
+ (cp >= 0x61 && cp <= 0x7A) ||
51698
+ cp === 0x2A || cp === 0x2B || cp === 0x2D || cp === 0x2E ||
51699
+ cp === 0x2F || cp === 0x40 || cp === 0x5F
51700
+ )
51701
+ }
51702
+
51703
+ /**
51704
+ * Normalizes the percent-encoding of a query or fragment component.
51705
+ *
51706
+ * Like `normalizePathEncoding`, but uses the query/fragment character set
51707
+ * (which additionally allows `?`) and decodes `.` since it has no dot-segment
51708
+ * meaning outside of a path.
51709
+ *
51710
+ * @param {string} input
51711
+ * @returns {string}
51712
+ */
51713
+ function normalizeQueryFragmentEncoding (input) {
51714
+ let output = ''
51715
+
51716
+ for (let i = 0; i < input.length; i++) {
51717
+ const ch = input[i]
51718
+ if (ch === '%' && i + 2 < input.length) {
51719
+ const hex = input.slice(i + 1, i + 3)
51720
+ if (isHexPair(hex)) {
51721
+ const normalizedHex = hex.toUpperCase()
51722
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16))
51723
+
51724
+ if (isUnreserved(decoded)) {
51725
+ output += decoded
51726
+ } else {
51727
+ output += '%' + normalizedHex
51728
+ }
51729
+
51730
+ i += 2
51731
+ continue
51732
+ }
51733
+ }
51734
+
51735
+ if (isQueryFragmentCharacter(ch)) {
51736
+ output += ch
51737
+ } else {
51738
+ const code = input.charCodeAt(i)
51739
+ if (code < 0x80) {
51740
+ output += isEscapeSafe(code) ? ch : BYTE_HEX[code]
51741
+ } else if (code < 0xD800 || code > 0xDFFF) {
51742
+ output += percentEncodeNonAscii(code)
51743
+ } else if (code <= 0xDBFF && i + 1 < input.length) {
51744
+ const low = input.charCodeAt(i + 1)
51745
+ if (low >= 0xDC00 && low <= 0xDFFF) {
51746
+ output += percentEncodeNonAscii(0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00))
51747
+ i++
51748
+ } else {
51749
+ output += percentEncodeNonAscii(0xFFFD)
51750
+ }
51751
+ } else {
51752
+ output += percentEncodeNonAscii(0xFFFD)
51753
+ }
51754
+ }
51023
51755
  }
51024
- return component
51756
+
51757
+ return output
51758
+ }
51759
+
51760
+ /**
51761
+ * Escapes a component while preserving existing valid percent escapes.
51762
+ *
51763
+ * @param {string} input
51764
+ * @returns {string}
51765
+ */
51766
+ function escapePreservingEscapes (input) {
51767
+ let output = ''
51768
+
51769
+ for (let i = 0; i < input.length; i++) {
51770
+ if (input[i] === '%' && i + 2 < input.length) {
51771
+ const hex = input.slice(i + 1, i + 3)
51772
+ if (isHexPair(hex)) {
51773
+ output += '%' + hex.toUpperCase()
51774
+ i += 2
51775
+ continue
51776
+ }
51777
+ }
51778
+
51779
+ output += escape(input[i])
51780
+ }
51781
+
51782
+ return output
51025
51783
  }
51026
51784
 
51027
51785
  /**
@@ -51032,18 +51790,24 @@ function recomposeAuthority (component) {
51032
51790
  const uriTokens = []
51033
51791
 
51034
51792
  if (component.userinfo !== undefined) {
51035
- uriTokens.push(component.userinfo)
51793
+ uriTokens.push(encodeUserinfo(component.userinfo))
51036
51794
  uriTokens.push('@')
51037
51795
  }
51038
51796
 
51039
51797
  if (component.host !== undefined) {
51040
- let host = unescape(component.host)
51798
+ let host = component.host
51041
51799
  if (!isIPv4(host)) {
51042
- const ipV6res = normalizeIPv6(host)
51043
- if (ipV6res.isIPV6 === true) {
51800
+ let ipV6res = normalizeIPv6(host)
51801
+ if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
51802
+ // Decode only unreserved bytes, once. In particular, keep %25 encoded
51803
+ // so it cannot introduce a second escape during recomposition.
51804
+ host = normalizePercentEncoding(host, true)
51805
+ ipV6res = normalizeIPv6(host)
51806
+ }
51807
+ if (ipV6res.isIPV6 === true || ipV6res.isIPVFuture === true) {
51044
51808
  host = `[${ipV6res.escapedHost}]`
51045
51809
  } else {
51046
- host = component.host
51810
+ host = reescapeHostDelimiters(host, false)
51047
51811
  }
51048
51812
  }
51049
51813
  uriTokens.push(host)
@@ -51060,7 +51824,15 @@ function recomposeAuthority (component) {
51060
51824
  module.exports = {
51061
51825
  nonSimpleDomain,
51062
51826
  recomposeAuthority,
51063
- normalizeComponentEncoding,
51827
+ reescapeHostDelimiters,
51828
+ normalizePercentEncoding,
51829
+ normalizePathEncoding,
51830
+ serializePathEncoding,
51831
+ normalizeQueryFragmentEncoding,
51832
+ encodeUserinfo,
51833
+ encodeQuery,
51834
+ encodeFragment,
51835
+ escapePreservingEscapes,
51064
51836
  removeDotSegments,
51065
51837
  isIPv4,
51066
51838
  isUUID,
@@ -72013,7 +72785,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"$schema":"http://json-schema.org/dra
72013
72785
  /***/ ((module) => {
72014
72786
 
72015
72787
  "use strict";
72016
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@pathmode/mcp-server","version":"1.20.1","publishConfig":{"access":"public"},"mcpName":"io.github.pathmodeio/mcp-server","description":"Deterministic intent preflight before your agent builds: six calibrated gates, keyless, no model call. Draft and sharpen specs in conversation, or connect a Pathmode workspace to sync intent and evidence across a team.","main":"dist/index.js","bin":{"pathmode-mcp":"dist/index.js"},"files":["dist/","manifest.json","icon.svg","README.md","skills/"],"scripts":{"build":"rm -rf dist && ncc build src/index.ts -o dist","dev":"ts-node src/index.ts","prepublishOnly":"npm run build"},"keywords":["pathmode","mcp","model-context-protocol","claude-code","claude-code-skills","agent-skills","cursor","windsurf","intent-engineering","intent-compiler","ai-agents","product-development","dependency-graph","strategic-planning"],"author":"Pathmode","license":"MIT","type":"commonjs","engines":{"node":">=18.0.0"},"homepage":"https://pathmode.io","dependencies":{"@modelcontextprotocol/sdk":"^1.12.1","gray-matter":"^4.0.3","zod":"^3.24.0"},"devDependencies":{"@types/node":"^25.1.0","@vercel/ncc":"^0.38.4","ts-node":"^10.9.2","typescript":"^5.9.3"}}');
72788
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@pathmode/mcp-server","version":"1.20.2","publishConfig":{"access":"public"},"mcpName":"io.github.pathmodeio/mcp-server","description":"Deterministic intent preflight before your agent builds: six calibrated gates, keyless, no model call. Draft and sharpen specs in conversation, or connect a Pathmode workspace to sync intent and evidence across a team.","main":"dist/index.js","bin":{"pathmode-mcp":"dist/index.js"},"files":["dist/","manifest.json","icon.svg","README.md","skills/"],"scripts":{"build":"rm -rf dist && ncc build src/index.ts -o dist","dev":"ts-node src/index.ts","prepublishOnly":"npm run build"},"keywords":["pathmode","mcp","model-context-protocol","claude-code","claude-code-skills","agent-skills","cursor","windsurf","intent-engineering","intent-compiler","ai-agents","product-development","dependency-graph","strategic-planning"],"author":"Pathmode","license":"MIT","type":"commonjs","engines":{"node":">=18.0.0"},"homepage":"https://pathmode.io","dependencies":{"@modelcontextprotocol/sdk":"^1.12.1","gray-matter":"^4.0.3","zod":"^3.24.0"},"overrides":{"@hono/node-server":"^1.19.17","body-parser":"^2.3.0","fast-uri":"^3.1.6","hono":"^4.13.5","ip-address":"^10.7.0","js-yaml":"^3.15.2"},"devDependencies":{"@types/node":"^25.1.0","@vercel/ncc":"^0.38.4","ts-node":"^10.9.2","typescript":"^5.9.3"}}');
72017
72789
 
72018
72790
  /***/ })
72019
72791
 
@@ -72473,6 +73245,16 @@ function startMcpServer() {
72473
73245
  return { content: [{ type: 'text', text: `Failed to fetch intent: ${e.message}` }] };
72474
73246
  }
72475
73247
  });
73248
+ const outcomeInputShape = zod_1.z.union([
73249
+ zod_1.z.string().trim().min(1),
73250
+ zod_1.z.object({
73251
+ id: zod_1.z.string().trim().min(1).optional(),
73252
+ text: zod_1.z.string().trim().min(1),
73253
+ priority: zod_1.z.enum(['must', 'should', 'could']).optional(),
73254
+ /** Null is meaningful on update: deliberately remove the stored recipe. */
73255
+ measurement: measurement_schema_1.outcomeMeasurementDefinitionShape.nullable().optional(),
73256
+ }),
73257
+ ]);
72476
73258
  cloudOnly.registerTool('get_intent_relations', {
72477
73259
  title: 'Get Intent Relations',
72478
73260
  description: 'Get the dependency graph for a specific intent. Shows what it depends on, enables, or blocks.',
@@ -73041,7 +73823,7 @@ function startMcpServer() {
73041
73823
  objective: zod_1.z.string().describe('Why this matters — the problem and who has it'),
73042
73824
  currentState: zod_1.z.string().optional().describe('How this works today, before the change: existing behavior, the workaround users rely on, what is broken. Tells implementing agents what must not regress. Omit for genuinely net-new capability.'),
73043
73825
  productId: zod_1.z.string().optional().describe('Product (Space) ID this intent belongs to. Omit it and the server resolves it when the workspace has exactly one real product. If it cannot, you get code PRODUCT_REQUIRED with the candidate list: ASK THE USER which product, then retry with an explicit id. Do not guess — a GitHub binding hangs off the product, so the product decides which repository the PR stamp and merge verification apply to, and a wrong guess surfaces much later as a merge that silently fails to verify.'),
73044
- outcomes: zod_1.z.array(zod_1.z.string()).optional().describe('Observable, testable state changes'),
73826
+ outcomes: zod_1.z.array(outcomeInputShape).optional().describe('Observable, testable state changes. Use the structured form to attach a stable saved-query recipe; for PostHog, source.queryRef is typically kind "saved_insight" plus the insight id.'),
73045
73827
  constraints: zod_1.z.array(zod_1.z.string()).optional().describe('Hard limits the implementation must respect'),
73046
73828
  healthMetrics: zod_1.z.array(zod_1.z.string()).optional().describe('What to monitor after shipping'),
73047
73829
  edgeCases: zod_1.z.array(zod_1.z.object({
@@ -73082,7 +73864,7 @@ function startMcpServer() {
73082
73864
  title: zod_1.z.string().optional().describe('New title'),
73083
73865
  objective: zod_1.z.string().optional().describe('Updated objective'),
73084
73866
  currentState: zod_1.z.string().optional().describe('Updated as-is behavior (how it works today). Pass an empty string to clear it.'),
73085
- outcomes: zod_1.z.array(zod_1.z.string()).optional().describe('Replace all outcomes'),
73867
+ outcomes: zod_1.z.array(outcomeInputShape).optional().describe('Replace all outcomes. Omit measurement on an outcome to preserve its stored recipe; send measurement: null to clear it.'),
73086
73868
  constraints: zod_1.z.array(zod_1.z.string()).optional().describe('Replace all constraints'),
73087
73869
  healthMetrics: zod_1.z.array(zod_1.z.string()).optional().describe('Replace all health metrics'),
73088
73870
  edgeCases: zod_1.z.array(zod_1.z.object({
@@ -73313,7 +74095,7 @@ function startMcpServer() {
73313
74095
  currentState: zod_1.z.string().optional().describe('How this works today, before the change — existing behavior and workarounds, so the implementation knows what must not regress. Omit for net-new capability.'),
73314
74096
  implementationContext: zod_1.z.string().optional().describe('What the repo actually looks like where this change lands: the files and modules involved, what already exists, what it would touch, how to verify it. You are in the working tree — go read it. Markdown, sub-headings welcome. Advisory: it never changes the readiness verdict, it just stops the implementing agent from rediscovering the codebase.'),
73315
74097
  productId: zod_1.z.string().optional().describe('Which product this intent belongs to (cloud mode only). Omit it and the server resolves it when the workspace has exactly one real product; if it cannot, the save fails with PRODUCT_REQUIRED and the candidate list, and you should ask the user which one and retry with an explicit id rather than guessing — a GitHub binding hangs off the product, so it decides which repository merge verification applies to.'),
73316
- outcomes: zod_1.z.array(zod_1.z.string()).describe('Observable, testable state changes'),
74098
+ outcomes: zod_1.z.array(outcomeInputShape).describe('Observable, testable state changes. The structured form may carry an optional provider-neutral saved-query measurement recipe.'),
73317
74099
  decisions: zod_1.z.array(zod_1.z.object({
73318
74100
  choice: zod_1.z.string(),
73319
74101
  ruledOut: zod_1.z.string().optional(),