Add sanitize.js with correct script load order to fix broken autocomplete#26
Merged
Merged
Conversation
…improve normalizeStreet in hazards.js Agent-Logs-Url: https://github.com/NickHamby/PotholeDodgerV2/sessions/698ed176-2f2b-4e8e-921c-67ec953885b8 Co-authored-by: NickHamby <271342652+NickHamby@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add string sanitization script to improve input handling
Add sanitize.js with correct script load order to fix broken autocomplete
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previous sanitization attempt broke autocomplete because
sanitize.jswas loaded after Leaflet, makingsanitizeInputundefined whenapp.jsfirst ran. This PR redoes that work withsanitize.jsloaded first.Changes
web/js/sanitize.js(new):sanitizeInput()— strips parens, unsafe punctuation, collapses whitespace; allowlist keeps letters, digits, spaces, commas, hyphens, slashesweb/index.html:sanitize.jsis now the first<script>tag, before the Leaflet CDNweb/js/app.js: Replace.value.trim()withsanitizeInput(inputEl.value)in bothattachAutocomplete()andrun()web/js/hazards.js: Replace flatABBR_MAP+normalizeStreet()with positional directional expansion and ZIP strippingKey
normalizeStreetimprovements: strips trailing ZIP codes before expansion, expands directionals only at string start/end (not globally), preserving correctness for street names like"East Ave".Original prompt
Implement the string sanitization plan as described in
docs/string-sanitization-plan.md. A previous attempt at this broke autocomplete becausesanitize.jswas loaded in the wrong position — the script tag was placed after Leaflet instead of before all app scripts, sosanitizeInputwas undefined whenapp.jstried to call it. This attempt must get the script load order exactly right.Changes required
1. Create
web/js/sanitize.js(new file)2. Update
web/index.htmlThe script load order is critical.
sanitize.jsMUST be the very first<script>tag — before Leaflet, before everything else. The final script block must look exactly like this:The current script block in
index.htmllooks like this (read the file to confirm):Add
<script src="js/sanitize.js"></script>as the FIRST line, before the Leaflet CDN script tag. Do NOT place it anywhere else.3. Update
web/js/app.jsIn
attachAutocomplete(): ReplaceinputEl.value.trim()withsanitizeInput(inputEl.value):In
run(): Replace the two.value.trim()calls withsanitizeInput():4. Update
web/js/hazards.jsReplace the existing
ABBR_MAPconstant andnormalizeStreet()function with this improved version. Do NOT touch anything else inhazards.js—getAllHazards(),getHazardsOnRoute(), and the coordinate bounding box logic must remain exactly as they are.Verification checklist — the agent MUST confirm all of these before opening the PR
This pull request was created from Copilot chat.