@poe-platform/safe-bash 0.1.48 → 0.1.50

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.
@@ -13801,21 +13801,31 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13801
13801
  this.writeVariable(state, "REPLY", line.value);
13802
13802
  } else {
13803
13803
  const separators = exact ? "" : state.variables.IFS ?? " \n";
13804
- const characters = Array.from(line.value);
13805
- const separator = (index) => index < characters.length && !line.escaped.has(index) && separators.includes(characters[index]);
13806
- const whitespace = (index) => separator(index) && /[ \t\n]/u.test(characters[index]);
13807
- let end = characters.length;
13808
- while (end > 0 && whitespace(end - 1)) end--;
13804
+ let end = 0;
13805
+ let offset = 0;
13806
+ let point = 0;
13807
+ for (const character of line.value) {
13808
+ offset += character.length;
13809
+ if (line.escaped.has(point) || !separators.includes(character) || !" \n".includes(character)) end = offset;
13810
+ point++;
13811
+ }
13809
13812
  let position = 0;
13810
- while (position < end && whitespace(position)) position++;
13813
+ point = 0;
13814
+ const separator = () => position < end && !line.escaped.has(point) && separators.includes(String.fromCodePoint(line.value.codePointAt(position)));
13815
+ const whitespace = () => separator() && " \n".includes(line.value[position]);
13816
+ const advance = () => {
13817
+ position += line.value.codePointAt(position) > 65535 ? 2 : 1;
13818
+ point++;
13819
+ };
13820
+ while (position < end && whitespace()) advance();
13811
13821
  const fields = [];
13812
- while (position < end) {
13822
+ while (position < end && fields.length < names.length) {
13813
13823
  const start = position;
13814
- while (position < end && !separator(position)) position++;
13824
+ while (position < end && !separator()) advance();
13815
13825
  fields.push({ start, end: position });
13816
- while (position < end && whitespace(position)) position++;
13817
- if (position < end && separator(position)) position++;
13818
- while (position < end && whitespace(position)) position++;
13826
+ while (position < end && whitespace()) advance();
13827
+ if (position < end && separator()) advance();
13828
+ while (position < end && whitespace()) advance();
13819
13829
  }
13820
13830
  for (let index = 0; index < names.length; index++) {
13821
13831
  if (state.readonlyVariables?.has(names[index])) {
@@ -13823,7 +13833,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13823
13833
  return index === names.length - 1 ? 1 : 2;
13824
13834
  }
13825
13835
  const field = fields[index];
13826
- await this.assignVariable(state, names[index], field ? characters.slice(field.start, index === names.length - 1 && fields.length > names.length ? end : field.end).join("") : "");
13836
+ await this.assignVariable(state, names[index], field ? line.value.slice(field.start, index === names.length - 1 && position < end ? end : field.end) : "");
13827
13837
  }
13828
13838
  }
13829
13839
  return line.terminated ? 0 : 1;
@@ -14575,6 +14585,21 @@ var InputCursor = class {
14575
14585
  signal.throwIfAborted();
14576
14586
  }
14577
14587
  };
14588
+ var ReadText = class {
14589
+ #chunks = [];
14590
+ #pending = [];
14591
+ append(value2) {
14592
+ if (!value2) return;
14593
+ this.#pending.push(value2);
14594
+ if (this.#pending.length === 1024) {
14595
+ this.#chunks.push(this.#pending.join(""));
14596
+ this.#pending.length = 0;
14597
+ }
14598
+ }
14599
+ finish() {
14600
+ return this.#chunks.join("") + this.#pending.join("");
14601
+ }
14602
+ };
14578
14603
  var ShellInput = class _ShellInput {
14579
14604
  constructor(source, budget, signal = budget.signal) {
14580
14605
  this.budget = budget;
@@ -14631,7 +14656,8 @@ var ShellInput = class _ShellInput {
14631
14656
  return this.#cursor.consume(this.signal, () => options2 ? this.readBounded(raw, options2) : this.readLine(raw));
14632
14657
  }
14633
14658
  async readBounded(raw, options2) {
14634
- const characters = [];
14659
+ const text = new ReadText();
14660
+ let characters = 0;
14635
14661
  const escaped = /* @__PURE__ */ new Set();
14636
14662
  const decoder3 = new TextDecoder("utf-8", { fatal: true });
14637
14663
  const delimiter = options2.delimiter ?? 10;
@@ -14676,18 +14702,21 @@ var ShellInput = class _ShellInput {
14676
14702
  escapedCharacter = true;
14677
14703
  }
14678
14704
  const decoded = decoder3.decode(Uint8Array.of(byte), { stream: true });
14705
+ let decodedCharacters = 0;
14679
14706
  for (const character of decoded) {
14680
14707
  if (escapedCharacter) {
14681
14708
  escapedCharacter = false;
14682
- escaped.add(characters.length);
14709
+ escaped.add(characters);
14683
14710
  }
14684
- characters.push(character);
14711
+ text.append(character);
14712
+ characters++;
14713
+ decodedCharacters++;
14685
14714
  }
14686
- units += options2.byteCount ? 1 : Array.from(decoded).length;
14715
+ units += options2.byteCount ? 1 : decodedCharacters;
14687
14716
  if (units === options2.count) terminated = true;
14688
14717
  }
14689
14718
  decoder3.decode();
14690
- return { value: characters.join(""), escaped, terminated };
14719
+ return { value: text.finish(), escaped, terminated };
14691
14720
  } catch (error) {
14692
14721
  if (error instanceof TypeError && error.message.includes("encoded data")) throw new Error("read: unsupported non-UTF-8 text boundary");
14693
14722
  throw error;
@@ -14739,17 +14768,21 @@ var ShellInput = class _ShellInput {
14739
14768
  }
14740
14769
  const value2 = new TextDecoder().decode(bytes).replace(/\0/gu, "");
14741
14770
  const escaped = /* @__PURE__ */ new Set();
14742
- if (raw) return { value: value2, escaped, terminated };
14743
- const characters = Array.from(value2);
14744
- const unescaped = [];
14745
- for (let index = 0; index < characters.length; index++) {
14746
- if (characters[index] === "\\") {
14747
- if (++index === characters.length) break;
14748
- escaped.add(unescaped.length);
14749
- }
14750
- unescaped.push(characters[index]);
14751
- }
14752
- return { value: unescaped.join(""), escaped, terminated };
14771
+ if (raw || !value2.includes("\\")) return { value: value2, escaped, terminated };
14772
+ const text = new ReadText();
14773
+ let characters = 0;
14774
+ for (let index = 0; index < value2.length; ) {
14775
+ const slash = value2.indexOf("\\", index);
14776
+ const span = value2.slice(index, slash < 0 ? value2.length : slash);
14777
+ text.append(span);
14778
+ for (let pointOffset = 0; pointOffset < span.length; pointOffset += span.codePointAt(pointOffset) > 65535 ? 2 : 1) characters++;
14779
+ if (slash < 0 || slash + 1 === value2.length) break;
14780
+ const character = String.fromCodePoint(value2.codePointAt(slash + 1));
14781
+ escaped.add(characters++);
14782
+ text.append(character);
14783
+ index = slash + 1 + character.length;
14784
+ }
14785
+ return { value: text.finish(), escaped, terminated };
14753
14786
  }
14754
14787
  close() {
14755
14788
  if (!this.#closing) {