Fix uncaught TypeError in "Show on map" operation.#2453
Open
lzandman wants to merge 3 commits into
Open
Conversation
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.
Description
Adding the Show on map operation with an input that resolves to only a single
coordinate value crashes the browser with an uncaught error:
This PR fixes #2420.
How to reproduce
Navigate to:
https://gchq.github.io/CyberChef/#recipe=Show_on_map(13,'Auto','%5C%5Cn')&input=MSwgMjQ
(input
1, 24, add "Show on Map" operation with the Input Delimiter set to\n)Root cause
The input
1, 24is comma-separated, but the recipe pins the Input Delimiterto
\n(newline). That mismatch derails the auto format-detection insrc/core/lib/ConvertCoordinates.mjs:findFormat()is called with the newline delimiter. Since1, 24contains nonewline, the whole string is treated as one coordinate. Splitting it on
whitespace yields two numbers (
1and24), so it is detected asDegrees Decimal Minutes.
\n, gets a single element, setsisPair = false, and interprets1, 24as a single DDM value:1° 24'=1.4°."1.4", not alatitude/longitude pair.
ShowOnMap.present()then emittedL.map(...).setView([1.4], 13)— a one-elementarray — and Leaflet threw
TypeError: Cannot read properties of null (reading 'lat')because the longitude was
undefined.The solution
ShowOnMap.run()now validates that the conversion produced a properlatitude/longitude pair. If it didn't, it throws a friendly
OperationErrorinstead of letting a single value flow through to the map:
Validation lives in
run()rather thanpresent()becausepresent()executesoutside the recipe's error handling, so an error thrown there would crash the bake
instead of surfacing as a message.
This converts an uncaught browser
TypeErrorinto a clear, actionable errormessage telling the user to check the input format and delimiter.
Testing
Added operation tests in
tests/operations/tests/ShowOnMap.mjs:51.5007, -0.1246) still renders the map.1, 24with\ndelimiter) now produces the helpful errormessage instead of crashing.
Also verified in Chrome:
1, 24with\ndelimiter): no more uncaughtTypeError; theoutput now shows "Could not show coordinates '1.4' on the map. Expected a
latitude and longitude pair - check that the input format and delimiter are
correct."
51.5007, -0.1246): map renders, tiles load, and the popup shows51.5007,-0.1246— behaviour unchanged.npx eslintpasses on the changed files.Files changed
src/core/operations/ShowOnMap.mjs— added latitude/longitude pair validation inrun().tests/operations/tests/ShowOnMap.mjs— new test file (regression + happy path).tests/operations/index.mjs— register the new test file.AI Disclosure
Claude Code used to assist in analyzing the bug and creating a fix.