Repository navigation
Escape text in ZmanimFormatter.toXML / toJSON, GeoLocation.toXML and Zman.toXML - #300
Merged
KosherJava merged 1 commit intoNov 6, 2026
Conversation
…Zman.toXML A location name (or zman label / description) containing ", &, < or a backslash was written verbatim, so the output was not well-formed XML or valid JSON. Text values are now escaped (XML entities; RFC 8259 JSON escapes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU
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.
The issue
ZmanimFormatter.toXML(),ZmanimFormatter.toJSON(),GeoLocation.toXML()andZman.toXML()write text values exactly as they are, without escaping, so the output is invalid XML or JSON when the text contains special characters.The edge case
A location name (or a zman label or description) containing a character that is special in XML or JSON:
&,<,>,"or', for exampleKfar Saba & Ra'anana.",\or a control character such as a newline.Location names often come from user input, a geocoder or a database, so these characters do show up in real data.
What happens
Any XML or JSON parser rejects the output, and code that builds an XML / JSON response from it ends up serving a broken document. Text that isn't escaped is also a markup injection point when the location name comes from users.
The fix
ZmanimFormatter:escapeXml: replaces& < > " 'with their entities.escapeJson: escapes"and\and writes control characters as escape sequences, as RFC 8259 requires.GeoLocation.null: Still written asnull, as before.Output for text without special characters is unchanged.
Tests
toXmlEscapesSpecialCharacters: Parses the output of all threetoXMLmethods with the JDK's XML parser and checks the escaped attribute.toJsonEscapesSpecialCharacters: Checks the escaped JSON string, including a newline.Both fail without the fix.
🤖 Generated with Claude Code
https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU