Add sanitizeInput() and improve normalizeStreet() for edge cases#24
Merged
Conversation
…ex.html Agent-Logs-Url: https://github.com/NickHamby/PotholeDodgerV2/sessions/be13c8ab-ca4e-4894-a848-cc4155488651 Co-authored-by: NickHamby <271342652+NickHamby@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add input sanitization and improve street normalization
Add sanitizeInput() and improve normalizeStreet() for edge cases
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.
Adds a
sanitizeInput()function for cleaning raw user input before Nominatim queries, and fixesnormalizeStreet()to correctly handle ZIP codes, positional directionals, and address fractions.New:
web/js/sanitize.jsStrips parentheticals, removes query-breaking characters, collapses whitespace — preserves commas (Nominatim separators), hyphens, and slashes:
web/js/hazards.js—normalizeStreet()rewriteABBR_MAPintoSTREET_TYPE_ABBRS+DIRECTIONAL_EXPAND— old flat map expandedE/W/N/Smid-string (e.g. inside "New" or "West"), causing false mismatches"8 1/2 W Canal St, 23220"→"west canal street")web/js/app.jsattachAutocomplete()andrun(): replaced.value.trim()withsanitizeInput(inputEl.value)web/index.html<script src="js/sanitize.js"></script>as the first script tag sosanitizeInputis available to all subsequent scriptsOriginal prompt
Implement the string sanitization plan as described in
docs/string-sanitization-plan.md. This adds a newsanitizeInput()function and improvesnormalizeStreet()to handle ZIP codes, positional directionals, and other edge cases.Changes required
1. Create
web/js/sanitize.js(new file)2. Update
web/js/hazards.jsReplace the existing
ABBR_MAPconstant andnormalizeStreet()function with the following improved version that handles ZIP codes and positional directionals:Do NOT change anything else in
hazards.js—getAllHazards(),getHazardsOnRoute(), and the coordinate bounding box logic from the previous PR are all unchanged.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/index.htmlAdd
<script src="js/sanitize.js"></script>as the first script tag, beforegeocode.js:5. Update
web/js/geocode.jsAdd Richmond bounding box to the Nominatim search URL (this was identified as a bug in a previous session —
geocodeAddresscurrently has no bounding box, so addresses can resolve outside Richmond):Also add
countrycodes=usto the autocomplete URL inweb/js/app.js(line withviewbox=-77.6,37.7,-77.2,37.4):