-
Notifications
You must be signed in to change notification settings - Fork 16
Fix auto-events href handling #79
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: v12
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Email Link Callback Overwrites `href` Variable
A variable shadowing bug occurs where the href
variable declared at line 81 is overwritten by a subsequent var href
declaration within the email case. Due to var
's function-scoping and hoisting, both declarations refer to the same variable. This causes the callback function to use the overwritten href
value instead of the one initially captured, defeating the original intent to prevent timing issues. Although email link callbacks execute immediately, this introduces fragility and potential for future bugs.
src/auto-events.js#L80-L141
Lines 80 to 141 in 8bf5d27
var href = element.getAttribute("href"); | |
var callback = function () { | |
if (!sent && !element.hasAttribute("target") && href) | |
document.location = href; | |
sent = true; | |
}; | |
if (window[saGlobal] && window[saGlobal + "_loaded"]) { | |
var hostname = element.hostname; | |
var pathname = element.pathname; | |
var event; | |
var metadata = { | |
title: element.getAttribute("title") || undefined, | |
}; | |
var url = element.href || undefined; | |
var useTitle = false; | |
if (optionsLink.title && element.hasAttribute("title")) { | |
var theTitle = element.getAttribute("title").trim(); | |
if (theTitle != "") useTitle = true; | |
} | |
if (useTitle) { | |
event = theTitle; | |
} else { | |
switch (type) { | |
case "outbound": { | |
event = hostname + (optionsLink.outboundFullUrl ? pathname : ""); | |
metadata.url = url; | |
break; | |
} | |
case "download": { | |
event = optionsLink.downloadsFullUrl | |
? hostname + pathname | |
: pathname.split("/").pop(); | |
metadata.url = url; | |
break; | |
} | |
case "email": { | |
var href = element.getAttribute("href"); | |
event = (href.split(":")[1] || "").split("?")[0]; | |
metadata.email = event; | |
break; | |
} | |
} | |
} | |
var clean = | |
type + | |
"_" + | |
event.replace(/[^a-z0-9]+/gi, "_").replace(/(^_+|_+$)/g, ""); | |
window[saGlobal](clean, metadata, callback); | |
log("collected " + clean); | |
return type === "email" | |
? callback() | |
: window.setTimeout(callback, 5000); |
BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
Summary
Testing
npm run build
npm run test:unit
https://chatgpt.com/codex/tasks/task_e_685b1a028b348323a7365cf673846e2e