livelocale 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ var __esm = (fn, res, err) => function __init() {
5
+ if (err) throw err[0];
6
+ try {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ } catch (e) {
9
+ throw err = [e], e;
10
+ }
6
11
  };
7
12
  var __export = (target, all) => {
8
13
  for (var name in all)
@@ -383,7 +388,8 @@ function createStudioServer(options) {
383
388
  res.end("Bad Request");
384
389
  return;
385
390
  }
386
- if (filePath !== studioDir && !filePath.startsWith(studioDir + path2.sep)) {
391
+ const relativePath = path2.relative(studioDir, filePath);
392
+ if (relativePath.startsWith("..") || path2.isAbsolute(relativePath)) {
387
393
  res.statusCode = 403;
388
394
  res.end("Forbidden");
389
395
  return;
@@ -1555,7 +1561,7 @@ function parseIcu(message) {
1555
1561
  parseMessage(0);
1556
1562
  return { args, error };
1557
1563
  }
1558
- var I18NEXT_RE = /\{\{\s*([^{}]*?)\s*\}\}/g;
1564
+ var I18NEXT_RE = /\{\{([^{}]*)\}\}/g;
1559
1565
  var NESTING_RE = /\$t\([^)]*\)/g;
1560
1566
  var PRINTF_RE = /%(?:\d+\$)?[-+ 0#]*\d*(?:\.\d+)?[sdifgxXoc]/g;
1561
1567
  var TAG_RE = /<\/?([A-Za-z][\w-]*|\d+)\b[^<>]*>/g;
@@ -3019,7 +3025,12 @@ function escapeAttribute(value) {
3019
3025
  }
3020
3026
  function injectFlagScript(html, src) {
3021
3027
  const tag = `<script src="${escapeAttribute(src)}"></script>`;
3022
- const cleaned = html.replace(EXISTING_FLAG_TAG, "");
3028
+ let cleaned = html;
3029
+ let previous;
3030
+ do {
3031
+ previous = cleaned;
3032
+ cleaned = cleaned.replace(EXISTING_FLAG_TAG, "");
3033
+ } while (cleaned !== previous);
3023
3034
  for (const pattern of [HEAD_OPEN2, HTML_OPEN2, DOCTYPE2]) {
3024
3035
  const match = pattern.exec(cleaned);
3025
3036
  if (match) {
@@ -3035,8 +3046,8 @@ var NO_REPO_WARNING = "exposeRepo is on but no GitHub repository was found; the
3035
3046
  function isPlainObject2(value) {
3036
3047
  return typeof value === "object" && value !== null && !Array.isArray(value);
3037
3048
  }
3038
- function toPosix(relative10) {
3039
- return relative10.split(path11.sep).join("/") || ".";
3049
+ function toPosix(relative11) {
3050
+ return relative11.split(path11.sep).join("/") || ".";
3040
3051
  }
3041
3052
  function isInside(parent, child) {
3042
3053
  const rel = path11.relative(parent, child);
@@ -3533,11 +3544,14 @@ function setNestedProperty(obj, keyPath, value) {
3533
3544
  let current = obj;
3534
3545
  for (let i = 0; i < keys.length; i++) {
3535
3546
  const key = keys[i];
3547
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
3548
+ throw new Error(`[livelocale] Forbidden key segment in path: "${keyPath}".`);
3549
+ }
3536
3550
  if (i === keys.length - 1) {
3537
3551
  current[key] = value;
3538
3552
  return;
3539
3553
  }
3540
- if (!(key in current) || current[key] === null || typeof current[key] !== "object" || Array.isArray(current[key])) {
3554
+ if (!Object.prototype.hasOwnProperty.call(current, key) || current[key] === null || typeof current[key] !== "object" || Array.isArray(current[key])) {
3541
3555
  current[key] = {};
3542
3556
  }
3543
3557
  current = current[key];
@@ -3810,6 +3824,13 @@ var nodeInflate = async (bytes, maxOutputLength) => {
3810
3824
  return result.buffer;
3811
3825
  };
3812
3826
 
3827
+ // src/core/strings.ts
3828
+ function trimTrailingSlashes(value) {
3829
+ let end = value.length;
3830
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
3831
+ return value.slice(0, end);
3832
+ }
3833
+
3813
3834
  // src/server/github-rest.ts
3814
3835
  var GitHubApiError = class extends Error {
3815
3836
  constructor(message, status) {
@@ -3842,7 +3863,7 @@ function encodeRefPath(ref) {
3842
3863
  }
3843
3864
  function createGitHubRest(config) {
3844
3865
  const repo = config.repo;
3845
- const apiBase = (config.apiBase ?? "https://api.github.com").replace(/\/+$/, "");
3866
+ const apiBase = trimTrailingSlashes(config.apiBase ?? "https://api.github.com");
3846
3867
  const fetchImpl = config.fetchImpl ?? globalThis.fetch;
3847
3868
  const owner = repo.split("/")[0] ?? "";
3848
3869
  if (!/^[\w.-]+\/[\w.-]+$/.test(repo)) {
@@ -4271,6 +4292,7 @@ var BIDI_CONTROL_RE = /[\u202a-\u202e\u2066-\u2069]/g;
4271
4292
  var NEWLINE_RE = /\r\n|\r|\n/g;
4272
4293
  var SPAN_CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
4273
4294
  var CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/g;
4295
+ var BACKSLASH_BEFORE_PIPE_RE = /\\(?=\|)/g;
4274
4296
  function cut(text, max) {
4275
4297
  if (text.length <= max) return text;
4276
4298
  let out = text.slice(0, max);
@@ -4300,7 +4322,7 @@ function codePointLabel(ch) {
4300
4322
  }
4301
4323
  function codeSpan(text, maxLength = DEFAULT_SPAN_LENGTH) {
4302
4324
  const truncated = text.length > maxLength ? `${cut(text, maxLength)}\u2026` : text;
4303
- const content = truncated.replace(NEWLINE_RE, "\u23CE").replace(BIDI_CONTROL_RE, codePointLabel).replace(SPAN_CONTROL_RE, codePointLabel).replace(/\|/g, "\\|");
4325
+ const content = truncated.replace(NEWLINE_RE, "\u23CE").replace(BIDI_CONTROL_RE, codePointLabel).replace(SPAN_CONTROL_RE, codePointLabel).replace(BACKSLASH_BEFORE_PIPE_RE, codePointLabel).replace(/\|/g, "\\|");
4304
4326
  if (content === "") return "` `";
4305
4327
  const fence = "`".repeat(longestBacktickRun(content) + 1);
4306
4328
  const pad = /^[` ]|[` ]$/.test(content) ? " " : "";
@@ -5940,8 +5962,8 @@ function planGitignore(projectDir) {
5940
5962
  if (parseGitignore(current).ignores("public/livelocale", true)) {
5941
5963
  return { path: ".gitignore", action: "unchanged" };
5942
5964
  }
5943
- const sep10 = current === "" || current.endsWith("\n") ? "" : "\n";
5944
- return { path: ".gitignore", action: "update", content: `${current}${sep10}${SHARE_GITIGNORE}
5965
+ const sep9 = current === "" || current.endsWith("\n") ? "" : "\n";
5966
+ return { path: ".gitignore", action: "update", content: `${current}${sep9}${SHARE_GITIGNORE}
5945
5967
  ` };
5946
5968
  }
5947
5969
  function planBuild(c) {