@miaskiewicz/turbo-dom 0.1.13 → 0.1.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miaskiewicz/turbo-dom",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1162,8 +1162,29 @@ export class Document extends Node {
1162
1162
  getElementsByClassName(cls) { const self = this; const classes = cls.split(/\s+/).filter(Boolean); return liveHTMLCollection(() => collectByClass(self, classes)); }
1163
1163
  contains(node) { return Node.prototype.contains.call(this, node); }
1164
1164
 
1165
- get cookie() { return this.__cookie || ''; }
1166
- set cookie(v) { this.__cookie = (this.__cookie ? this.__cookie + '; ' : '') + v; }
1165
+ // cookie jar: store name=value, strip attributes (path/Secure/SameSite/…),
1166
+ // dedupe by name, honor deletion via max-age<=0 or a past expires.
1167
+ get cookie() {
1168
+ if (!this.__cookieJar) return '';
1169
+ return [...this.__cookieJar].map(([k, v]) => `${k}=${v}`).join('; ');
1170
+ }
1171
+ set cookie(str) {
1172
+ if (!this.__cookieJar) this.__cookieJar = new Map();
1173
+ const parts = String(str).split(';');
1174
+ const pair = parts.shift();
1175
+ const eq = pair.indexOf('=');
1176
+ if (eq === -1) return;
1177
+ const name = pair.slice(0, eq).trim();
1178
+ if (!name) return;
1179
+ const value = pair.slice(eq + 1).trim();
1180
+ const attrs = parts.map((a) => a.trim().toLowerCase());
1181
+ const maxAge = attrs.find((a) => a.startsWith('max-age='));
1182
+ const expires = attrs.find((a) => a.startsWith('expires='));
1183
+ const deleted = (maxAge && parseInt(maxAge.slice(8), 10) <= 0) ||
1184
+ (expires && new Date(expires.slice(8)).getTime() <= Date.now());
1185
+ if (deleted) this.__cookieJar.delete(name);
1186
+ else this.__cookieJar.set(name, value);
1187
+ }
1167
1188
 
1168
1189
  // document state (honest defaults for a headless, focused, loaded page)
1169
1190
  get visibilityState() { return 'visible'; }
@@ -40,7 +40,7 @@ export function createEnvironment(html = '<!doctype html><html><head></head><bod
40
40
  document.__load(soa); // drops __cache + __kids overlay, keeps the buffer if reused
41
41
  win.resetGlobals();
42
42
  document.__active = null;
43
- document.__cookie = '';
43
+ document.__cookieJar = null;
44
44
  },
45
45
  };
46
46
  }