@poe-platform/safe-bash 0.1.675 → 0.1.677

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +3 -2
  2. package/dist/safe-bash/chunks/{chunk-AJMYOERL.js → chunk-MP5J46WX.js} +6 -6
  3. package/dist/safe-bash/chunks/{chunk-AJMYOERL.js.map → chunk-MP5J46WX.js.map} +2 -2
  4. package/dist/safe-bash/commands/text-programs/awk-syntax.d.ts.map +1 -1
  5. package/dist/safe-bash/commands/text-programs/awk-syntax.js +5 -3
  6. package/dist/safe-bash/commands/text-programs/awk-syntax.js.map +1 -1
  7. package/dist/safe-bash/commands/yq/index.browser.js +1 -1
  8. package/dist/safe-bash/commands/yq/parser.js +5 -5
  9. package/dist/safe-bash/commands/yq/parser.js.map +1 -1
  10. package/dist/safe-bash/core.browser.js +68 -19
  11. package/dist/safe-bash/core.browser.js.map +3 -3
  12. package/dist/safe-bash/playwright/adapter.d.ts +19 -10
  13. package/dist/safe-bash/playwright/adapter.d.ts.map +1 -1
  14. package/dist/safe-bash/playwright/adapter.js.map +1 -1
  15. package/dist/safe-bash/playwright/frame-snapshot.d.ts.map +1 -1
  16. package/dist/safe-bash/playwright/frame-snapshot.js +138 -22
  17. package/dist/safe-bash/playwright/frame-snapshot.js.map +1 -1
  18. package/dist/safe-bash/playwright/network-policy.d.ts.map +1 -1
  19. package/dist/safe-bash/playwright/network-policy.js +37 -29
  20. package/dist/safe-bash/playwright/network-policy.js.map +1 -1
  21. package/dist/safe-bash/shell/arithmetic.d.ts +1 -1
  22. package/dist/safe-bash/shell/arithmetic.d.ts.map +1 -1
  23. package/dist/safe-bash/shell/arithmetic.js +37 -2
  24. package/dist/safe-bash/shell/arithmetic.js.map +1 -1
  25. package/dist/safe-bash/shell/parser.d.ts +1 -0
  26. package/dist/safe-bash/shell/parser.d.ts.map +1 -1
  27. package/dist/safe-bash/shell/parser.js +10 -4
  28. package/dist/safe-bash/shell/parser.js.map +1 -1
  29. package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
  30. package/dist/safe-bash/shell/runtime.js +15 -9
  31. package/dist/safe-bash/shell/runtime.js.map +1 -1
  32. package/package.json +2 -2
@@ -25,7 +25,7 @@ import {
25
25
  rawValues,
26
26
  stringify,
27
27
  yqCommands
28
- } from "./chunks/chunk-AJMYOERL.js";
28
+ } from "./chunks/chunk-MP5J46WX.js";
29
29
  import {
30
30
  CurlError,
31
31
  cloudflareWorkerNetworkLimits,
@@ -12802,10 +12802,11 @@ var AwkParser = class {
12802
12802
  pattern = this.expression();
12803
12803
  if (this.accept(",")) end = this.expression();
12804
12804
  }
12805
- const action = this.at("{") ? this.block() : { kind: "print", formatted: false, args: [] };
12805
+ let action = { kind: "print", formatted: false, args: [] };
12806
+ if (this.at("{")) action = this.block();
12807
+ else if (!this.at("\n") && !this.at(";") && !this.ended()) throw new ProgramError(`expected rule separator at byte ${this.token.offset}`);
12806
12808
  program.rules.push({ ...pattern ? { pattern } : {}, ...end ? { end } : {}, action });
12807
12809
  }
12808
- if (!this.at("\n") && !this.at(";") && !this.ended() && !this.at("{") && !this.at("BEGIN") && !this.at("END") && !this.at("function")) throw new ProgramError(`expected rule separator at byte ${this.token.offset}`);
12809
12810
  this.separators();
12810
12811
  }
12811
12812
  for (const call of this.calls) {
@@ -40094,14 +40095,47 @@ function parseArithmetic(source2, offset = 0, budget = new ParseBudget()) {
40094
40095
  if (cursor < tokens2.length) error("Unexpected arithmetic token");
40095
40096
  return tree;
40096
40097
  }
40097
- function arithmeticEnd(source2, start) {
40098
+ function arithmeticEnd(source2, start, allowSubshell = false) {
40098
40099
  let depth = 0;
40100
+ let quote5 = "";
40101
+ let ansiQuote = false;
40102
+ const quotedSubstitutions = [];
40099
40103
  for (let position = start; position < source2.length; position++) {
40100
40104
  const character = source2[position];
40105
+ if (allowSubshell) {
40106
+ if (character === "\\" && (quote5 !== "'" || ansiQuote)) {
40107
+ position++;
40108
+ continue;
40109
+ }
40110
+ if (quote5 === '"' && character === "$" && source2[position + 1] === "(") {
40111
+ if (quotedSubstitutions.length >= 64) throw new ShellSyntaxError("Syntax nesting exceeds 64", position);
40112
+ quotedSubstitutions.push(depth);
40113
+ depth++;
40114
+ position++;
40115
+ quote5 = "";
40116
+ continue;
40117
+ }
40118
+ if (quote5) {
40119
+ if (character === quote5) quote5 = "";
40120
+ continue;
40121
+ }
40122
+ if (character === "'" || character === '"' || character === "`") {
40123
+ quote5 = character;
40124
+ ansiQuote = character === "'" && source2[position - 1] === "$";
40125
+ continue;
40126
+ }
40127
+ }
40101
40128
  if (character === "(") depth++;
40102
40129
  if (character === ")") {
40103
40130
  if (depth === 0 && source2[position + 1] === ")") return position;
40104
- if (--depth < 0) break;
40131
+ if (--depth < 0) {
40132
+ if (allowSubshell) return -1;
40133
+ break;
40134
+ }
40135
+ if (quotedSubstitutions.at(-1) === depth) {
40136
+ quotedSubstitutions.pop();
40137
+ quote5 = '"';
40138
+ }
40105
40139
  }
40106
40140
  }
40107
40141
  throw new ShellSyntaxError("Unterminated arithmetic expression", start);
@@ -41044,7 +41078,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
41044
41078
  }
41045
41079
  this.error("Unterminated delimiter expansion syntax");
41046
41080
  }
41047
- word(terminator, enclosingQuoted = false, literal = false, arithmetic2 = false) {
41081
+ word(terminator, enclosingQuoted = false, literal = false, arithmetic2 = false, arithmeticExpansion = false) {
41048
41082
  this.budget.admit();
41049
41083
  const offset = this.position;
41050
41084
  const reduction = this.printedNewlineReduction;
@@ -41183,7 +41217,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
41183
41217
  const spelling2 = expansionSpellings.get(parts.at(-1));
41184
41218
  if (spelling2) spelling2.end = Math.min(this.position + 1, this.source.length);
41185
41219
  if (this.position < this.source.length) this.position++;
41186
- } else if (current === "\\") {
41220
+ } else if (current === "\\" && (!arithmeticExpansion || ["$", "`", '"', "\\", "\n"].includes(this.source[this.position + 1] ?? ""))) {
41187
41221
  if (this.source[this.position + 1] !== "\n") plain = false;
41188
41222
  this.position++;
41189
41223
  if (this.position === this.source.length) {
@@ -41567,6 +41601,7 @@ var Parser2 = class {
41567
41601
  }
41568
41602
  commandInner() {
41569
41603
  this.budget.admit();
41604
+ const arithmeticCommandEnd = this.is("(") && this.lexer.source.startsWith("((", this.current.offset) ? arithmeticEnd(this.lexer.source, this.current.offset + 2, true) : -1;
41570
41605
  let command7;
41571
41606
  if (this.is("[[")) {
41572
41607
  const start = this.current.end;
@@ -41638,9 +41673,9 @@ var Parser2 = class {
41638
41673
  this.lexer.conditional = false;
41639
41674
  this.advance();
41640
41675
  command7 = { kind: "conditional", expression, source: source2, redirects: [] };
41641
- } else if (this.is("(") && this.lexer.source.startsWith("((", this.current.offset)) {
41676
+ } else if (arithmeticCommandEnd !== -1) {
41642
41677
  const start = this.current.offset + 2;
41643
- const end = arithmeticEnd(this.lexer.source, start);
41678
+ const end = arithmeticCommandEnd;
41644
41679
  const source2 = this.lexer.source.slice(start, end);
41645
41680
  command7 = { kind: "arithmetic", expression: prepareArithmetic(source2, this.budget), source: source2, redirects: [] };
41646
41681
  this.lexer.position = end + 2;
@@ -41888,6 +41923,10 @@ function parseArraySubscript(source2, budget, byteLocale2 = false, depth = 0, by
41888
41923
  const lexer = new Lexer2(budget, source2, depth, [], 0, byteLocale2, void 0, false, void 0, 0, false, void 0, byteSource, syntax);
41889
41924
  return lexer.word("\0");
41890
41925
  }
41926
+ function parseArithmeticExpansion(source2, budget, byteLocale2 = false, depth = 0, line = 1, syntax) {
41927
+ const lexer = new Lexer2(budget, source2, depth, [], line - 1, byteLocale2, void 0, false, void 0, 0, false, void 0, false, captureShellSyntax(syntax));
41928
+ return lexer.word("\0", true, false, false, true);
41929
+ }
41891
41930
  function parseBraceWord(source2, opaque, budget) {
41892
41931
  budget.admit(source2.length + 1);
41893
41932
  const lexer = new Lexer2(budget, source2, 0);
@@ -53581,20 +53620,30 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
53581
53620
  return "";
53582
53621
  }
53583
53622
  if (part.kind === "arithmetic") {
53623
+ const allocation = this.budget.values.scope();
53584
53624
  try {
53585
- return String(evaluatePositionalArithmetic(part.expression, {
53586
- parseBudget: this.budget.parsing,
53587
- positional: state.positional,
53588
- arg0: state.arg0 ?? "virtual-bash",
53589
- owner: arrayStore(state)?.owner,
53590
- maximumBytes: this.budget.limits.maxExpansionBytes,
53591
- checkpoint: () => this.signal.throwIfAborted(),
53592
- requireParameter: (name2, value3) => this.requireParameter(value3, name2, state, io, part.line),
53593
- limit: () => this.budget.fail("maxExpansionBytes")
53594
- }, (prepared) => evaluateArithmetic(prepared, this.arithmeticVariables(state, io.diagnosticLine ?? part.line), this.budget.parsing)));
53625
+ let program = part.expression;
53626
+ if (program.error) {
53627
+ const word = parseArithmeticExpansion(
53628
+ program.source,
53629
+ this.budget.parsing,
53630
+ byteLocale(state.variables),
53631
+ state.depth + (io.parameterDepth ?? 0),
53632
+ io.diagnosticLine ?? part.line,
53633
+ state.extensions?.syntax
53634
+ );
53635
+ const operandIO = this.parameterOperandIO(word, state, { ...io, [valueScope]: allocation });
53636
+ const fields4 = await this.valueWord(word, state, operandIO, false, false, true);
53637
+ const source2 = shellValueText(concatShellValues(fields4, allocation));
53638
+ this.signal.throwIfAborted();
53639
+ program = prepareArithmetic(source2, this.budget.parsing);
53640
+ }
53641
+ return String(evaluateArithmetic(program, this.arithmeticVariables(state, io.diagnosticLine ?? part.line), this.budget.parsing));
53595
53642
  } catch (error) {
53596
53643
  this.rethrowArithmeticControl(error);
53597
53644
  throw new ExpansionFailure(message2(error, this.budget.onInternalError), io.diagnosticLine ?? part.line);
53645
+ } finally {
53646
+ allocation.close();
53598
53647
  }
53599
53648
  }
53600
53649
  if (part.kind === "substitution") {