@yuneta/gobj-js 7.28.0 → 7.29.0

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.
@@ -426,7 +426,7 @@ var Event_Type = class {
426
426
  }
427
427
  };
428
428
  function tab() {
429
- return " ".repeat(Math.max(1, __inside__ * 2));
429
+ return " ".repeat(Math.max(1, __inside__ * 4));
430
430
  }
431
431
  var __trace_machine_format__ = 1;
432
432
  function gobj_set_trace_machine_format(format) {
@@ -7543,28 +7543,43 @@ function debounce(func, wait = 0, immediate = false) {
7543
7543
  * Build a URL/path from segments, ensuring exactly one '/'
7544
7544
  * between each part.
7545
7545
  *
7546
- * - The first segment keeps its leading '/' (absolute) or
7547
- * not (relative).
7548
- * - Trailing '/' is stripped from every segment.
7549
- * - Leading '/' is stripped from every segment except the first.
7546
+ * - The first segment is the ROOT: it keeps its leading '/'
7547
+ * (absolute) or not (relative), and its trailing '/' are
7548
+ * stripped -- but a root made only of '/' stays "/".
7549
+ * - Leading and trailing '/' are stripped from every later
7550
+ * segment, and duplicate '/' inside it are collapsed.
7551
+ * - '.' and '..' of the later segments are resolved, and '..'
7552
+ * never rises above the root: ("/store", "../../etc") is
7553
+ * "/store/etc".
7550
7554
  * - Empty/null/undefined segments are skipped.
7551
7555
  *
7552
- * Mirrors the C helper build_path() from gobj-c/src/helpers.c.
7556
+ * Mirrors the C helper build_path() from gobj-c/src/helpers.c
7557
+ * (tests/build_path.test.js pins the same cases). Up to 7.28.1
7558
+ * a root "/" was lost (("/", "tmp") gave "tmp") and '.'/'..'
7559
+ * were kept as they came.
7553
7560
  ************************************************************/
7554
7561
  function build_path(...segments) {
7555
- let result = "";
7556
- let i = 0;
7562
+ let root = null;
7563
+ let tail = [];
7557
7564
  for (let segment of segments) {
7558
7565
  if (segment == null || segment === "") continue;
7559
7566
  segment = String(segment);
7560
- if (i === 0) segment = segment.replace(/\/+$/, "");
7561
- else segment = segment.replace(/^\/+/, "").replace(/\/+$/, "");
7562
- if (segment === "") continue;
7563
- if (i > 0) result += "/";
7564
- result += segment;
7565
- i++;
7567
+ if (root === null) {
7568
+ root = segment.replace(/(.)\/+$/, "$1");
7569
+ continue;
7570
+ }
7571
+ for (let component of segment.split("/")) {
7572
+ if (component === "" || component === ".") continue;
7573
+ if (component === "..") {
7574
+ tail.pop();
7575
+ continue;
7576
+ }
7577
+ tail.push(component);
7578
+ }
7566
7579
  }
7567
- return result;
7580
+ if (root === null) return "";
7581
+ if (tail.length === 0) return root;
7582
+ return root + (root.endsWith("/") ? "" : "/") + tail.join("/");
7568
7583
  }
7569
7584
  /***************************************
7570
7585
  * Flat json (id -> value)