-
Notifications
You must be signed in to change notification settings - Fork 112
fix: referential equalities DOS #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
This seems to introduce a regression in the following case. import superjson from 'superjson';
const circularSet = new Set();
circularSet.add(circularSet);
const json = superjson.stringify(circularSet);
const result = superjson.parse(json);
if (result.has(result)) {
console.log("✅ Reference preserved");
} else {
console.error("❌ Reference broken: Set does not contain itself");
console.log(result);
} |
|
Also found this case that seems to regress import superjson from 'superjson';
const sharedRegex = /\s+/;
const root = {
a: sharedRegex,
b: sharedRegex
};
const json = superjson.stringify(root);
const result = superjson.parse(json);
if (result.a === result.b) {
console.log("✅ Shared reference preserved");
} else {
console.error("❌ Shared reference lost: result.a !== result.b");
} |
|
Thanks! I found a fix for the shared regex, will take a look at the circular set after the weekend. If you find a solution i'm all ears! |
|
Managed to fix the circular set, but the diff is becoming more and more unwieldly the more I fix stuff. I'm less convinced of this approach now, but going through the motions seems to be a good way of expanding our test coverage. @JeremyMoeglich if you could try to find some more breakages, that'd be wonderful! |
|
Found this case. import superjson from 'superjson';
const outer = new Set();
const inner = new Set();
// outer -> inner
outer.add(inner);
// inner -> outer
inner.add(outer);
const json = superjson.stringify(outer);
const result = superjson.parse(json);
const resultInner = result.values().next().value;
if (resultInner instanceof Set && resultInner.has(result)) {
console.log("✅ Success: Nested circular Set reference preserved");
} else {
console.error("❌ Mismatch: Reference broken.");
} |
|
Another case import superjson from 'superjson';
const inner = [/a/];
const root = [inner, inner];
try {
const json = superjson.stringify(root);
const _ = superjson.parse(json);
} catch (e) {
console.error(`❌ threw: ${e}`);
} |
|
Another case: import superjson from "superjson";
const ta = new Uint8Array(0);
const inner = [ta, ta];
const root = [inner, inner];
const s1 = superjson.stringify(root);
const roundtripped = superjson.parse(s1);
const s2 = superjson.stringify(roundtripped);
if (s1 !== s2) {
console.error("❌ mismatch: restringified !== stringified");
console.log(s1);
console.log(s2);
} else {
console.log("✅ ok: restringified === stringified");
} |
Closes #346