Skip to content

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

Open
wants to merge 1 commit into
base: v12
Choose a base branch
from

Conversation

adriaandotcom
Copy link
Collaborator

Summary

  • avoid using dynamic href in auto-events callback
  • add regression test for changed href
  • build latest auto-events script

Testing

  • npm run build
  • npm run test:unit

https://chatgpt.com/codex/tasks/task_e_685b1a028b348323a7365cf673846e2e

Copy link

@cursor cursor bot left a 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

scripts/src/auto-events.js

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);

Fix in Cursor


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 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant