Skip to content

Commit 68afd5c

Browse files
Replace chr() functions with json.dumps for cleaner email escaping
- Address GitHub comment requesting 'normal strings' instead of chr(39)/chr(92) - Use json.dumps for proper email escaping in JavaScript strings - Maintains XSS protection while improving code readability - Eliminates f-string syntax conflicts that required chr() workaround Co-Authored-By: Alek <[email protected]>
1 parent a3ee8dc commit 68afd5c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

pcweb/pages/pricing/header.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import re
23
import urllib.parse
34
from typing import Any, Literal
@@ -196,7 +197,7 @@ def submit(self, form_data: dict[str, Any]):
196197
yield QuoteFormState.send_demo_event(form_data)
197198

198199
yield rx.call_script(
199-
f"try {{ signals.identify('{email.replace(chr(39), chr(92) + chr(39))}'); }} catch(e) {{ console.warn('Signals identify failed:', e); }}"
200+
f"try {{ signals.identify({json.dumps(email)}); }} catch(e) {{ console.warn('Signals identify failed:', e); }}"
200201
)
201202

202203
if self.is_small_company():

pcweb/signup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import json
23
import os
34
from datetime import datetime
45
from typing import Any
@@ -101,6 +102,6 @@ def signup(
101102
self.add_contact_to_loops(email)
102103
self.signed_up = True
103104
return [
104-
rx.call_script(f"try {{ signals.identify('{email.replace(chr(39), chr(92) + chr(39))}'); }} catch(e) {{ console.warn('Signals identify failed:', e); }}"),
105+
rx.call_script(f"try {{ signals.identify({json.dumps(email)}); }} catch(e) {{ console.warn('Signals identify failed:', e); }}"),
105106
rx.toast.success("Thanks for signing up to the Newsletter!")
106107
]

0 commit comments

Comments
 (0)