@poe-platform/safe-bash 0.1.747 → 0.1.749

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.
@@ -13431,7 +13431,7 @@ function getCompiledSyncPatternRegex(pattern) {
13431
13431
  return compiled;
13432
13432
  }
13433
13433
  function tryMatchesPatternSync(pattern, value2, work, ignoreCase = false, extglob = false) {
13434
- if (Array.from !== defaultArrayFrom || ignoreCase || pattern.length >= 128 || value2.length > 512) return void 0;
13434
+ if (Array.from !== defaultArrayFrom || ignoreCase || pattern.length >= 128) return void 0;
13435
13435
  let hasBracketOrQmark = false;
13436
13436
  for (let i = 0; i < pattern.length; i++) {
13437
13437
  const c = pattern.charCodeAt(i);
@@ -56443,9 +56443,20 @@ async function leaf(node, context2) {
56443
56443
  return node.operator === "!=" ? !match : match;
56444
56444
  }
56445
56445
  if (node.operator === "<" || node.operator === ">") {
56446
- cLocale(context2);
56447
56446
  await charge(context2, shellValueByteLength(left) + shellValueByteLength(right));
56448
- const order = compareUtf8(left, right);
56447
+ let order;
56448
+ if (cCollation(context2.locale)) {
56449
+ order = compareUtf8(left, right);
56450
+ } else {
56451
+ if (!utf8Locale(context2.locale)) unsupported("collation locale");
56452
+ const locale = context2.locale.split(".")[0].split("_").join("-");
56453
+ try {
56454
+ if (Intl.Collator.supportedLocalesOf([locale]).length === 0) unsupported("collation locale");
56455
+ order = new Intl.Collator(locale).compare(left, right);
56456
+ } catch {
56457
+ unsupported("collation locale");
56458
+ }
56459
+ }
56449
56460
  return node.operator === "<" ? order < 0 : order > 0;
56450
56461
  }
56451
56462
  await charge(context2, left.length + right.length);
@@ -75593,7 +75604,7 @@ var Runtime = class _Runtime {
75593
75604
  }
75594
75605
  }
75595
75606
  if (command7.kind === "conditional") {
75596
- if (rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(command7.expression, 0, rawState)) return false;
75607
+ if (rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(command7.expression, 0, rawState, true)) return false;
75597
75608
  const checkCondNoFile = (e) => {
75598
75609
  if (e.kind === "nonempty") return this.isPureSyncValueWord(e.operand, rawState);
75599
75610
  if (e.kind === "unary") return (e.operator === "-n" || e.operator === "-z" || e.operator === "-v" || syncConditionalFileUnaryOps.has(e.operator) && this._isMemoryBackingFs && this.canFastMemoryRedirect && this.budget.limits.maxFileSystemOperations >= 1e3 && (this._fileWrites === void 0 || this._fileWrites.size === 0) && (this._outputFiles === void 0 || this._outputFiles.size === 0)) && this.isPureSyncValueWord(e.operand, rawState);
@@ -75869,8 +75880,9 @@ var Runtime = class _Runtime {
75869
75880
  }
75870
75881
  return false;
75871
75882
  }
75872
- canSyncConditional(expr, depth = 0, rawState) {
75883
+ canSyncConditional(expr, depth = 0, rawState, requireTotal = false) {
75873
75884
  if (depth > 8) return false;
75885
+ if (requireTotal && (expr.kind === "unary" && syncConditionalFileUnaryOps.has(expr.operator) || expr.kind === "binary" && expr.operator !== "==" && expr.operator !== "=" && expr.operator !== "!=" && expr.operator !== "=~")) return false;
75874
75886
  const okWord = (w) => !_Runtime.wordMayMutate(w) || rawState !== void 0 && this.isPureSyncValueWord(w, rawState);
75875
75887
  if (expr.kind === "nonempty") return okWord(expr.operand);
75876
75888
  if (expr.kind === "unary") return (expr.operator === "-n" || expr.operator === "-z" || expr.operator === "-v" || syncConditionalFileUnaryOps.has(expr.operator)) && okWord(expr.operand);
@@ -75886,8 +75898,8 @@ var Runtime = class _Runtime {
75886
75898
  }
75887
75899
  return expr.operator === "<" || expr.operator === ">" || expr.operator === "-eq" || expr.operator === "-ne" || expr.operator === "-lt" || expr.operator === "-le" || expr.operator === "-gt" || expr.operator === "-ge";
75888
75900
  }
75889
- if (expr.kind === "not") return this.canSyncConditional(expr.operand, depth + 1, rawState);
75890
- if (expr.kind === "and" || expr.kind === "or") return this.canSyncConditional(expr.left, depth + 1, rawState) && this.canSyncConditional(expr.right, depth + 1, rawState);
75901
+ if (expr.kind === "not") return this.canSyncConditional(expr.operand, depth + 1, rawState, requireTotal);
75902
+ if (expr.kind === "and" || expr.kind === "or") return this.canSyncConditional(expr.left, depth + 1, rawState, requireTotal) && this.canSyncConditional(expr.right, depth + 1, rawState, requireTotal);
75891
75903
  return false;
75892
75904
  }
75893
75905
  tryEvalFastMemoryFileUnary(op, rawVal, rawState) {
@@ -78992,40 +79004,7 @@ var Runtime = class _Runtime {
78992
79004
  if (part.indirect) {
78993
79005
  return false;
78994
79006
  }
78995
- const sel = getArraySelector(part);
78996
- if (sel !== void 0) {
78997
- if (rawState.nounset) return false;
78998
- if (sel.kind === "members" || sel.kind === "keys") {
78999
- if (part.operator !== void 0) {
79000
- if (sel.kind === "members" && !part.keys && !part.length && !part.substring && part.quoted && (sel.separator === "*" || allowAt && sel.separator === "@") && this.budget.limits.maxExpansionBytes === Infinity && !rawState.nocasematch) {
79001
- if ((part.operator === "#" || part.operator === "##" || part.operator === "%" || part.operator === "%%") && part.alternate && part.alternate.parts.length === 1 && part.alternate.parts[0].kind === "text" && (!hasGlobOrEscape(part.alternate.parts[0].value, true) || !part.alternate.parts[0].quoted && Boolean(tryCompileTrimGlobToRegex(part.alternate.parts[0].value, part.operator, !!rawState.extglob)))) continue;
79002
- if ((part.operator === "/" || part.operator === "//" || part.operator === "/#" || part.operator === "/%") && part.alternate && part.alternate.parts.length === 1 && part.alternate.parts[0].kind === "text" && part.alternate.parts[0].value.length > 0 && (!hasGlobOrEscape(part.alternate.parts[0].value, true) || !part.alternate.parts[0].quoted && Boolean(tryCompileFixedGlobToRegex(part.alternate.parts[0].value, part.operator, !!rawState.extglob))) && (!part.replacement || part.replacement.parts.length === 0 || part.replacement.parts.length === 1 && part.replacement.parts[0].kind === "text" && !part.replacement.parts[0].value.includes("&") && !part.replacement.parts[0].value.includes("\\") && !part.replacement.parts[0].value.startsWith("~"))) continue;
79003
- if ((part.operator === "^" || part.operator === "^^" || part.operator === "," || part.operator === ",,") && (!part.alternate || part.alternate.parts.length === 0)) continue;
79004
- }
79005
- return false;
79006
- }
79007
- if (part.length) {
79008
- if (part.substring) return false;
79009
- continue;
79010
- }
79011
- if (part.quoted && (sel.separator === "*" || allowAt && sel.separator === "@") && this.budget.limits.maxExpansionBytes === Infinity && (!part.substring || sel.kind === "members" && part.substring.offset.parts.every((p) => p.kind === "text" || p.kind === "variable" && !p.operator && !p.substring && !p.length) && (!part.substring.length || part.substring.length.parts.every((p) => p.kind === "text" || p.kind === "variable" && !p.operator && !p.substring && !p.length)))) {
79012
- continue;
79013
- }
79014
- return false;
79015
- }
79016
- if (sel.kind === "element") {
79017
- if (part.substring) {
79018
- return false;
79019
- }
79020
- if (part.operator === void 0) continue;
79021
- if ((part.operator === "-" || part.operator === ":-" || part.operator === "+" || part.operator === ":+") && part.alternate && !part.length) continue;
79022
- if ((part.operator === "^" || part.operator === "^^" || part.operator === "," || part.operator === ",,") && (!part.alternate || part.alternate.parts.length === 0) && !part.length) continue;
79023
- if (!part.length && !rawState.nocasematch && this.budget.limits.maxExpansionBytes === Infinity) {
79024
- if ((part.operator === "#" || part.operator === "##" || part.operator === "%" || part.operator === "%%") && part.alternate && part.alternate.parts.length === 1 && part.alternate.parts[0].kind === "text" && !hasGlobOrEscape(part.alternate.parts[0].value, true)) continue;
79025
- if ((part.operator === "/" || part.operator === "//" || part.operator === "/#" || part.operator === "/%") && part.alternate && part.alternate.parts.length === 1 && part.alternate.parts[0].kind === "text" && part.alternate.parts[0].value.length > 0 && !hasGlobOrEscape(part.alternate.parts[0].value, true) && (!part.replacement || part.replacement.parts.length === 0 || part.replacement.parts.length === 1 && part.replacement.parts[0].kind === "text" && !part.replacement.parts[0].value.includes("&") && !part.replacement.parts[0].value.includes("\\") && !part.replacement.parts[0].value.startsWith("~"))) continue;
79026
- }
79027
- return false;
79028
- }
79007
+ if (getArraySelector(part) !== void 0) {
79029
79008
  return false;
79030
79009
  }
79031
79010
  if (part.length || part.substring || part.operator !== void 0) {
@@ -79164,10 +79143,14 @@ var Runtime = class _Runtime {
79164
79143
  } else if (w0Plain === "grep") {
79165
79144
  if (plainOps.length !== opCount || this.evalSyncGrep([], plainOps, Boolean(rawState.errexit)) === void 0) return false;
79166
79145
  } else if (w0Plain === "awk") {
79167
- if (plainOps.length !== opCount || this.evalSyncAwk([], plainOps) === void 0) return false;
79146
+ const input3 = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79147
+ if (plainOps.length !== opCount || input3 === void 0) return false;
79148
+ const lines3 = input3.length === 0 ? [] : input3.split("\n");
79149
+ if (input3.endsWith("\n")) lines3.pop();
79150
+ if (this.evalSyncAwk(lines3, plainOps) === void 0) return false;
79168
79151
  } else if (w0Plain === "jq") {
79169
79152
  if (plainOps.length !== opCount) return false;
79170
- const jqIn = this.extractLoopInvariantJqInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79153
+ const jqIn = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79171
79154
  if (jqIn === void 0 || this.evalSyncJq(jqIn, plainOps) === void 0) return false;
79172
79155
  } else if (w0Plain === "wc") {
79173
79156
  if (opCount !== 1 || this.normalizeSyncWcFlag(op0) === void 0) return false;
@@ -79184,7 +79167,7 @@ var Runtime = class _Runtime {
79184
79167
  } else if (w0Plain === "paste") {
79185
79168
  if (plainOps.length !== opCount || this.evalSyncPaste([], plainOps) === void 0) return false;
79186
79169
  } else if (w0Plain === "numfmt") {
79187
- const nmCheck = this.extractLoopInvariantJqInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79170
+ const nmCheck = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79188
79171
  if (nmCheck === void 0 || plainOps.length !== opCount || this.evalSyncNumfmt(nmCheck.split("\n"), plainOps) === void 0) return false;
79189
79172
  }
79190
79173
  }
@@ -79268,14 +79251,19 @@ var Runtime = class _Runtime {
79268
79251
  } else if (sName === "sed") {
79269
79252
  if (this.evalSyncSed([], sPlainArgs) === void 0) return false;
79270
79253
  } else if (sName === "awk") {
79271
- if (this.evalSyncAwk([], sPlainArgs) === void 0) return false;
79254
+ if (sIdx !== 1) return false;
79255
+ const input3 = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79256
+ if (input3 === void 0) return false;
79257
+ const lines3 = input3.length === 0 ? [] : input3.split("\n");
79258
+ if (input3.endsWith("\n")) lines3.pop();
79259
+ if (this.evalSyncAwk(lines3, sPlainArgs) === void 0) return false;
79272
79260
  } else if (sName === "grep") {
79273
79261
  if (this.evalSyncGrep([], sPlainArgs, Boolean(rawState.errexit)) === void 0) return false;
79274
79262
  } else if (sName === "tr") {
79275
79263
  if (this.evalSyncTr("", sPlainArgs) === void 0) return false;
79276
79264
  } else if (sName === "jq") {
79277
79265
  if (sIdx !== 1) return false;
79278
- const jqIn = this.extractLoopInvariantJqInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79266
+ const jqIn = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79279
79267
  if (jqIn === void 0 || this.evalSyncJq(jqIn, sPlainArgs) === void 0) return false;
79280
79268
  } else if (sName === "base64") {
79281
79269
  if (sPlainArgs.length !== 0) return false;
@@ -79287,7 +79275,7 @@ var Runtime = class _Runtime {
79287
79275
  if (this.evalSyncPaste([], sPlainArgs) === void 0) return false;
79288
79276
  } else if (sName === "numfmt") {
79289
79277
  if (sIdx !== 1) return false;
79290
- const nmCheck = this.extractLoopInvariantJqInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79278
+ const nmCheck = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79291
79279
  if (nmCheck === void 0 || this.evalSyncNumfmt(nmCheck.split("\n"), sPlainArgs) === void 0) return false;
79292
79280
  } else if (sName === "rev") {
79293
79281
  if (sPlainArgs.length !== 0) return false;
@@ -79351,46 +79339,15 @@ var Runtime = class _Runtime {
79351
79339
  }
79352
79340
  return void 0;
79353
79341
  }
79354
- execSyncUnsetStep(step, rawState, io, monitor, touched) {
79342
+ execSyncUnsetStep(step, rawState, monitor, touched) {
79355
79343
  const uVars = step.unsetVars;
79356
- const store = monitor.store;
79357
79344
  let lastExpanded = "";
79358
- for (let ui = 0; ui < uVars.length; ui++) {
79359
- const uvn = uVars[ui];
79360
- if (uvn.charCodeAt(0) === 64) {
79361
- const wIdx = Number(uvn.slice(1));
79362
- const wu = step.cmd.words[wIdx];
79363
- const tExpanded = this.fastValueWord(wu, rawState, io, false, false, false, false, 0, step.line);
79364
- lastExpanded = tExpanded;
79365
- const bracket = tExpanded.indexOf("[");
79366
- if (bracket > 0 && tExpanded.endsWith("]") && store) {
79367
- const arrName = tExpanded.slice(0, bracket);
79368
- const subStr = tExpanded.slice(bracket + 1, -1);
79369
- const binding = store.get(arrName);
79370
- if (binding) {
79371
- if (binding.associative) {
79372
- const id = fastStringHexIdentity(subStr);
79373
- const existingKey = binding.keys.get(id);
79374
- if (existingKey !== void 0) {
79375
- binding.remove(existingKey.index);
79376
- store.changed(monitor.chargeInternal(syncRestorationCharge, syncRestorationTickets), arrName);
79377
- }
79378
- } else {
79379
- const idxNum = /^(?:0|[1-9][0-9]{0,8})$/.test(subStr) ? Number(subStr) : resolveSimpleArithOperand(subStr, rawState, monitor, store, this._syncArithRawWriteOnly ? this._syncArithTouched : void 0);
79380
- const resolvedIdx = idxNum !== void 0 ? idxNum >= 0 ? idxNum : binding.maximum + 1 + idxNum : void 0;
79381
- if (resolvedIdx !== void 0 && resolvedIdx >= 0 && binding.values.has(resolvedIdx)) {
79382
- binding.remove(resolvedIdx);
79383
- store.changed(monitor.chargeInternal(syncRestorationCharge, syncRestorationTickets), arrName);
79384
- }
79385
- }
79386
- }
79387
- }
79388
- } else {
79389
- delete rawState.variables[uvn];
79390
- monitor.proxy.exported.delete(uvn);
79391
- touched.add(uvn);
79392
- lastExpanded = uvn;
79393
- }
79345
+ for (const uvn of uVars) {
79346
+ delete rawState.variables[uvn];
79347
+ rawState.exported.delete(uvn);
79348
+ monitor.proxy.exported.delete(uvn);
79349
+ touched.add(uvn);
79350
+ lastExpanded = uvn;
79394
79351
  }
79395
79352
  return lastExpanded;
79396
79353
  }
@@ -79408,16 +79365,6 @@ var Runtime = class _Runtime {
79408
79365
  const vn = cmd.words[i].plain;
79409
79366
  if (vn && startIdx === 1 && hasShellFunction(rawState, vn)) return void 0;
79410
79367
  if (!vn || vn.startsWith("-") || !isShellIdentifier(vn) || controlNames.has(vn) || vn === "OPTIND" || rawState.readonlyVariables?.has(vn) || rawState.variableAttributes?.get(vn) || store?.get(vn) || stateMonitor(rawState)?.hasOverlay(vn) || rawState.locals.some((f) => f.has(vn))) {
79411
- const wu = cmd.words[i];
79412
- const p02 = wu.parts[0];
79413
- const pLast = wu.parts[wu.parts.length - 1];
79414
- const m = p02?.kind === "text" ? /^([a-zA-Z_][a-zA-Z0-9_]*)\[/.exec(p02.value) : void 0;
79415
- const arrName = m?.[1];
79416
- const b = arrName ? store?.get(arrName) : void 0;
79417
- if (arrName && b && b.references === 1 && !store.watches.has(arrName) && !rawState.readonlyVariables?.has(arrName) && !hasUnpreparedLocal(rawState, arrName) && !stateMonitor(rawState)?.hasOverlay(arrName) && pLast?.kind === "text" && pLast.value.endsWith("]") && this.isPureSyncValueWord(wu, rawState) && (p02.quoted || rawState.noglob || !rawState.nullglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync5(this.backingFs, rawState.cwd)?.size === 0)) {
79418
- vars.push(`@${i}`);
79419
- continue;
79420
- }
79421
79368
  return void 0;
79422
79369
  }
79423
79370
  vars.push(vn);
@@ -79697,7 +79644,7 @@ var Runtime = class _Runtime {
79697
79644
  if (bc.kind === "arithmetic") {
79698
79645
  if (bc.redirects.length !== 0 || bc.expression.error || bc.expression.hasMutation || bc.expression.hasSubscript || !isSafeSmiProgram(bc.expression) || !this.canSyncArithmeticWithoutFault(bc.expression.tree, rawState, bc.line ?? 1)) return false;
79699
79646
  } else if (bc.kind === "conditional") {
79700
- if (bc.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(bc.expression, 0, rawState)) return false;
79647
+ if (bc.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(bc.expression, 0, rawState, true)) return false;
79701
79648
  if (bc.expression.kind === "binary" && bc.expression.operator === "=~") return false;
79702
79649
  } else if (!this.extractPosixBracketCondExpr(bc, rawState, true, br.body)) {
79703
79650
  return false;
@@ -79727,7 +79674,7 @@ var Runtime = class _Runtime {
79727
79674
  if (pipeline.negate || pipeline.commands.length !== 1) return false;
79728
79675
  const cmd = pipeline.commands[0];
79729
79676
  const canSyncLoopCondCmd = (c) => {
79730
- if (c.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(c.expression, 0, rawState)) return false;
79677
+ if (c.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(c.expression, 0, rawState, true)) return false;
79731
79678
  const checkLeaf = (e) => {
79732
79679
  if (e.kind === "nonempty") return this.isPureSyncValueWord(e.operand, rawState);
79733
79680
  if (e.kind === "unary") return (e.operator === "-n" || e.operator === "-z" || e.operator === "-v" || syncConditionalFileUnaryOps.has(e.operator) && this._isMemoryBackingFs && this.canFastMemoryRedirect && this.budget.limits.maxFileSystemOperations >= 1e3 && (this._fileWrites === void 0 || this._fileWrites.size === 0) && (this._outputFiles === void 0 || this._outputFiles.size === 0)) && this.isPureSyncValueWord(e.operand, rawState);
@@ -79970,6 +79917,7 @@ var Runtime = class _Runtime {
79970
79917
  return false;
79971
79918
  }
79972
79919
  const assignment = this.assignment(w0);
79920
+ if (assignment && (assignment.name === "LC_ALL" || assignment.name === "LC_CTYPE" || assignment.name === "LC_COLLATE" || assignment.name === "LANG")) return false;
79973
79921
  if (!assignment || assignment.append && this.budget.limits.maxExpansionBytes !== Infinity || assignment.name === "OPTIND" || assignment.name === "PIPESTATUS" || assignment.name.includes("[") || rawState.readonlyVariables?.has(assignment.name) || rawState.variableAttributes?.get(assignment.name) || store?.get(assignment.name) || !this.isPureSyncValueWord(assignment.value, rawState)) {
79974
79922
  return false;
79975
79923
  }
@@ -80971,7 +80919,7 @@ var Runtime = class _Runtime {
80971
80919
  }
80972
80920
  whileArithProg = condCmd.expression;
80973
80921
  } else if (condCmd.kind === "conditional") {
80974
- if (condCmd.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(condCmd.expression, 0, rawState)) return void 0;
80922
+ if (condCmd.redirects.length !== 0 || rawState.nocasematch || byteLocale(rawState.variables) || !this.canSyncConditional(condCmd.expression, 0, rawState, true)) return void 0;
80975
80923
  const checkWhileCond = (e, depth) => {
80976
80924
  if (e.kind === "nonempty") return this.isPureSyncValueWord(e.operand, rawState);
80977
80925
  if (e.kind === "unary") return (e.operator === "-n" || e.operator === "-z" || e.operator === "-v") && this.isPureSyncValueWord(e.operand, rawState);
@@ -81558,7 +81506,7 @@ var Runtime = class _Runtime {
81558
81506
  if (rawState.allexport) monitor.proxy.exported.add(varName);
81559
81507
  } else {
81560
81508
  monitor.values.invalidate(varName);
81561
- monitor.proxy.exported.delete(varName);
81509
+ if (!rawState.exported.has(varName)) monitor.proxy.exported.delete(varName);
81562
81510
  }
81563
81511
  }
81564
81512
  }
@@ -81781,7 +81729,7 @@ ${s1}
81781
81729
  };
81782
81730
  return visit(script2);
81783
81731
  }
81784
- extractLoopInvariantJqInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState) {
81732
+ extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState) {
81785
81733
  const w0 = cmd.words[0]?.plain;
81786
81734
  const resolveInvariantWord = (w) => {
81787
81735
  if (w.plain !== void 0) return w.plain;
@@ -81795,10 +81743,10 @@ ${s1}
81795
81743
  }
81796
81744
  return void 0;
81797
81745
  };
81798
- if (w0 === "jq" || w0 === "numfmt") {
81746
+ if (w0 === "jq" || w0 === "numfmt" || w0 === "awk") {
81799
81747
  if (hasSingleHereStringRedir) {
81800
81748
  const resolved = resolveInvariantWord(cmd.redirects[0].target);
81801
- return resolved !== void 0 ? resolved.trim() : void 0;
81749
+ return resolved !== void 0 ? resolved + "\n" : void 0;
81802
81750
  }
81803
81751
  if (this._fileWrites?.size || this._outputFiles?.size) return void 0;
81804
81752
  if ([this._activeLoopBodyScript, this._activeLoopCondScript].some((script2) => script2 && !this.isFileReadOnlyScript(script2, rawState))) return void 0;
@@ -81806,12 +81754,12 @@ ${s1}
81806
81754
  if (!fPlain || fPlain.startsWith("-") || fPlain === "/dev/stdin") return void 0;
81807
81755
  const vCheck = this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, fPlain), false);
81808
81756
  if (!vCheck || vCheck.byteLength > 16384 || vCheck.includes(0)) return void 0;
81809
- return sharedSyncPipeDecoder.decode(vCheck).trim();
81757
+ return sharedSyncPipeDecoder.decode(vCheck);
81810
81758
  }
81811
81759
  if (w0 === "cat") {
81812
81760
  if (hasSingleHereStringRedir) {
81813
81761
  const resolved = resolveInvariantWord(cmd.redirects[0].target);
81814
- return resolved !== void 0 ? resolved.trim() : void 0;
81762
+ return resolved !== void 0 ? resolved + "\n" : void 0;
81815
81763
  }
81816
81764
  if (this._fileWrites?.size || this._outputFiles?.size) return void 0;
81817
81765
  if ([this._activeLoopBodyScript, this._activeLoopCondScript].some((script2) => script2 && !this.isFileReadOnlyScript(script2, rawState))) return void 0;
@@ -81819,11 +81767,11 @@ ${s1}
81819
81767
  if (!fPlain || fPlain.startsWith("-") || fPlain === "/dev/stdin") return void 0;
81820
81768
  const vCheck = this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, fPlain), false);
81821
81769
  if (!vCheck || vCheck.byteLength > 16384 || vCheck.includes(0)) return void 0;
81822
- return sharedSyncPipeDecoder.decode(vCheck).trim();
81770
+ return sharedSyncPipeDecoder.decode(vCheck);
81823
81771
  }
81824
81772
  if (w0 === "echo" && cmd.words.length === 2) {
81825
81773
  const resolved = resolveInvariantWord(cmd.words[1]);
81826
- if (resolved !== void 0 && !resolved.startsWith("-")) return resolved.trim();
81774
+ if (resolved !== void 0 && !resolved.startsWith("-")) return resolved + "\n";
81827
81775
  return void 0;
81828
81776
  }
81829
81777
  if (w0 === "printf" && cmd.words.length >= 2) {
@@ -81834,7 +81782,7 @@ ${s1}
81834
81782
  args.push(r);
81835
81783
  }
81836
81784
  const formatted3 = tryFastPrintf(args);
81837
- return formatted3 !== void 0 ? formatted3.trim() : void 0;
81785
+ return formatted3;
81838
81786
  }
81839
81787
  return void 0;
81840
81788
  }
@@ -82217,7 +82165,7 @@ ${s1}
82217
82165
  break;
82218
82166
  }
82219
82167
  if (step.unsetVars !== void 0) {
82220
- lastArg = this.execSyncUnsetStep(step, rawState, io, monitor, touched);
82168
+ lastArg = this.execSyncUnsetStep(step, rawState, monitor, touched);
82221
82169
  rawState.status = 0;
82222
82170
  continue;
82223
82171
  }
@@ -82720,7 +82668,7 @@ ${s1}
82720
82668
  break;
82721
82669
  }
82722
82670
  if (step.unsetVars !== void 0) {
82723
- lastArg = this.execSyncUnsetStep(step, rawState, io, monitor, touched);
82671
+ lastArg = this.execSyncUnsetStep(step, rawState, monitor, touched);
82724
82672
  rawState.status = 0;
82725
82673
  onUpdate({ lastCmd, lastArg });
82726
82674
  continue;
@@ -82894,7 +82842,7 @@ ${s1}
82894
82842
  break;
82895
82843
  }
82896
82844
  if (step.unsetVars !== void 0) {
82897
- lastArg = this.execSyncUnsetStep(step, rawState, io, monitor, touched);
82845
+ lastArg = this.execSyncUnsetStep(step, rawState, monitor, touched);
82898
82846
  rawState.status = 0;
82899
82847
  continue;
82900
82848
  }
@@ -90749,13 +90697,13 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
90749
90697
  }
90750
90698
  if (st === "floor") return typeof item === "number" ? [Math.floor(item)] : void 0;
90751
90699
  if (st === "ceil") return typeof item === "number" ? [Math.ceil(item)] : void 0;
90752
- if (st === "round") return typeof item === "number" ? [Math.round(item)] : void 0;
90700
+ if (st === "round") return typeof item === "number" ? [Math.sign(item) * Math.round(Math.abs(item))] : void 0;
90753
90701
  if (st === "abs") return typeof item === "number" ? [Math.abs(item)] : void 0;
90754
- if (st === "utf8bytelength") return typeof item === "string" ? [import_buffer.Buffer.byteLength(item, "utf8")] : void 0;
90702
+ if (st === "utf8bytelength") return typeof item === "string" ? [fastSharedTextEncoder.encode(item).byteLength] : void 0;
90755
90703
  if (st === "explode") return typeof item === "string" ? [Array.from(item, (c) => c.codePointAt(0))] : void 0;
90756
90704
  if (st === "implode") {
90757
90705
  if (!Array.isArray(item) || !item.every((x) => typeof x === "number" && Number.isInteger(x) && x >= 0 && x <= 1114111)) return void 0;
90758
- return [String.fromCodePoint(...item)];
90706
+ return [item.map((cp) => String.fromCodePoint(cp >= 55296 && cp <= 57343 ? 65533 : cp)).join("")];
90759
90707
  }
90760
90708
  if (st === "transpose") {
90761
90709
  if (!Array.isArray(item) || !item.every((row) => Array.isArray(row))) return void 0;
@@ -90768,14 +90716,18 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
90768
90716
  return [trans];
90769
90717
  }
90770
90718
  const idxFnM = /^(index|rindex|indices)\(\s*"([^"\\]*)"\s*\)$/.exec(st);
90771
- if (idxFnM && typeof item === "string") {
90719
+ if (idxFnM && (typeof item === "string" || Array.isArray(item))) {
90772
90720
  const fn = idxFnM[1];
90773
90721
  const sub = idxFnM[2];
90774
90722
  const found = [];
90775
- if (sub.length > 0) {
90723
+ if (Array.isArray(item)) {
90724
+ for (let i = 0; i < item.length; i++) {
90725
+ if (item[i] === sub) found.push(i);
90726
+ }
90727
+ } else if (sub.length > 0) {
90776
90728
  let pos = 0;
90777
90729
  while ((pos = item.indexOf(sub, pos)) !== -1) {
90778
- found.push(Array.from(item.slice(0, pos)).length);
90730
+ found.push(fastSharedTextEncoder.encode(item.slice(0, pos)).byteLength);
90779
90731
  pos += 1;
90780
90732
  }
90781
90733
  }
@@ -91898,6 +91850,7 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91898
91850
  if (m[1] !== void 0) {
91899
91851
  const tm = /^(\$(?:[0-9]+|NF)|NR|NF)\s*(==|!=|>=|<=|>|<)\s*(-?[0-9]+(?:\.[0-9]+)?|"[^"$\\]*")\s*\?\s*(\$(?:[0-9]+|NF)|"[^"$\\]*"|-?[0-9]+(?:\.[0-9]+)?)\s*:\s*(\$(?:[0-9]+|NF)|"[^"$\\]*"|-?[0-9]+(?:\.[0-9]+)?)$/.exec(m[1].trim());
91900
91852
  if (!tm) return void 0;
91853
+ if (tm[2] === ">") return void 0;
91901
91854
  parts.push({ kind: "ternary", lhs: tm[1], op: tm[2], rhs: tm[3], yes: tm[4], no: tm[5] });
91902
91855
  } else if (m[2] !== void 0) parts.push({ kind: "int", token: m[2] });
91903
91856
  else if (m[3] !== void 0) parts.push({ kind: "case", fn: m[3] === "toupper" ? "upper" : "lower", token: m[4] });
@@ -91980,8 +91933,9 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91980
91933
  } else if (p.kind === "int") {
91981
91934
  const idx = p.token === "NF" ? fields3.length : Number(p.token);
91982
91935
  const s = idx === 0 ? l : idx >= 1 && idx <= fields3.length ? fields3[idx - 1] : "";
91983
- const n = Number(/^[ \t]*([+-]?(?:\d+(?:\.\d*)?|\.\d+))/.exec(s)?.[1] ?? 0);
91984
- out += String(Math.trunc(n));
91936
+ const n = number(inputValue(s));
91937
+ if (!Number.isFinite(n)) return void 0;
91938
+ out += text(numeric2(Math.trunc(n)));
91985
91939
  } else if (p.kind === "ternary") {
91986
91940
  const resolveAtom = (tok) => {
91987
91941
  if (tok.startsWith('"') && tok.endsWith('"')) return tok.slice(1, -1);
@@ -91995,15 +91949,10 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91995
91949
  };
91996
91950
  const lv = resolveAtom(p.lhs);
91997
91951
  const rv = resolveAtom(p.rhs);
91998
- const isStrCmp = p.rhs.startsWith('"');
91999
- let cond = false;
92000
- if (isStrCmp) {
92001
- cond = p.op === "==" ? lv === rv : p.op === "!=" ? lv !== rv : p.op === ">" ? lv > rv : p.op === "<" ? lv < rv : p.op === ">=" ? lv >= rv : lv <= rv;
92002
- } else {
92003
- const ln = Number(lv) || 0;
92004
- const rn = Number(rv) || 0;
92005
- cond = p.op === "==" ? ln === rn : p.op === "!=" ? ln !== rn : p.op === ">" ? ln > rn : p.op === "<" ? ln < rn : p.op === ">=" ? ln >= rn : ln <= rn;
92006
- }
91952
+ const left = p.lhs === "NR" || p.lhs === "NF" ? numeric2(Number(lv)) : inputValue(lv);
91953
+ const right = p.rhs.startsWith('"') ? string(rv) : numeric2(Number(rv));
91954
+ const comparison = compare2(left, right, "%.6g");
91955
+ const cond = p.op === "==" ? comparison === 0 : p.op === "!=" ? comparison !== 0 : p.op === ">" ? comparison > 0 : p.op === "<" ? comparison < 0 : p.op === ">=" ? comparison >= 0 : comparison <= 0;
92007
91956
  out += resolveAtom(cond ? p.yes : p.no);
92008
91957
  } else if (p.kind === "arith") {
92009
91958
  const vals = [];
@@ -92222,12 +92171,13 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
92222
92171
  const parseDelims = (s) => {
92223
92172
  if (s.length === 0) return [""];
92224
92173
  const res = [];
92174
+ const chars = Array.from(s);
92225
92175
  const escapes2 = { b: "\b", f: "\f", n: "\n", r: "\r", t: " ", v: "\v", "0": "" };
92226
- for (let i = 0; i < s.length; i++) {
92227
- const ch = s[i];
92176
+ for (let i = 0; i < chars.length; i++) {
92177
+ const ch = chars[i];
92228
92178
  if (ch === "\\") {
92229
- if (i + 1 >= s.length) return void 0;
92230
- const esc = s[++i];
92179
+ if (i + 1 >= chars.length) return void 0;
92180
+ const esc = chars[++i];
92231
92181
  res.push(escapes2[esc] ?? esc);
92232
92182
  } else {
92233
92183
  res.push(ch);
@@ -169,9 +169,24 @@ async function leaf(node, context) {
169
169
  return node.operator === "!=" ? !match : match;
170
170
  }
171
171
  if (node.operator === "<" || node.operator === ">") {
172
- cLocale(context);
173
172
  await charge(context, shellValueByteLength(left) + shellValueByteLength(right));
174
- const order = compareUtf8(left, right);
173
+ let order;
174
+ if (cCollation(context.locale)) {
175
+ order = compareUtf8(left, right);
176
+ }
177
+ else {
178
+ if (!utf8Locale(context.locale))
179
+ unsupported("collation locale");
180
+ const locale = context.locale.split(".")[0].split("_").join("-");
181
+ try {
182
+ if (Intl.Collator.supportedLocalesOf([locale]).length === 0)
183
+ unsupported("collation locale");
184
+ order = new Intl.Collator(locale).compare(left, right);
185
+ }
186
+ catch {
187
+ unsupported("collation locale");
188
+ }
189
+ }
175
190
  return node.operator === "<" ? order < 0 : order > 0;
176
191
  }
177
192
  await charge(context, left.length + right.length);
@@ -381,7 +381,7 @@ function getCompiledSyncPatternRegex(pattern) {
381
381
  return compiled;
382
382
  }
383
383
  export function tryMatchesPatternSync(pattern, value, work, ignoreCase = false, extglob = false) {
384
- if (Array.from !== defaultArrayFrom || ignoreCase || pattern.length >= 128 || value.length > 512)
384
+ if (Array.from !== defaultArrayFrom || ignoreCase || pattern.length >= 128)
385
385
  return undefined;
386
386
  let hasBracketOrQmark = false;
387
387
  for (let i = 0; i < pattern.length; i++) {
@@ -532,7 +532,7 @@ export declare class Runtime {
532
532
  private isVarUnmutatedInScript;
533
533
  private isVarUnmutatedInActiveLoop;
534
534
  private isFileReadOnlyScript;
535
- private extractLoopInvariantJqInput;
535
+ private extractLoopInvariantInput;
536
536
  private canSyncPrintfInductionBody;
537
537
  private isSyncPrintfCallOk;
538
538
  private isSimpleRedirectEchoWord;