|
Meta tags:
description=Description
Fixes #1092.
XML.mustEscape() is shared by two callers that need opposite answers for TAB (0x9), LF (0xA) and CR (0xD):
XML.escape() uses it to decide what to escape when serializing.
XMLTokener.unescapeEntity() uses it to reject invalid numeric character references when parsing.
#1070 added those three codepoints to the valid-range clause so that unescape(
) works again (#1059). A side effect was that the serialization path stopped escaping literal TAB/LF/CR: XML.toString() and JSONML.toString() now write them as literal characters. Conforming XML parsers normalize whitespace, so a value like Lettuce\nTomato loses its line breaks when the generated XML is read back by any standard parser — the attribute value comes back as Lettuce Tomato (or with collapsed whitespace), and XML.toJSONObject(XML.toString(o)) does not return the original string.
This PR splits the two concerns:
XML.mustEscape() again returns true for every ISO control character (serialization). Literal TAB/LF/CR are written as ,
,
, which was the behavior before #1070.
New XML.isValidXmlCharacter() checks the XML 1.0 character range (#x9 #xA #xD [#x20-#xD7FF] [#xE000-#xFFFD] [#x10000-#x10FFFF]).
XMLTokener.unescapeEntity() validates numeric character references against isValidXmlCharacter() instead, so ,
and
keep being accepted — the #1059/#1070 parsing behavior is unchanged.
Tests
Three new tests in XMLTest:
testEscapesLiteralWhitespaceControlCharsOnSerialization — XML.toString() writes
/ /
for literal TAB/LF/CR. Fails on master.
testWhitespaceControlCharsRoundTripThroughXml — XML.toJSONObject(XML.toString(o)) returns the original value with the line break intact.
testJSONMLToStringEscapesLiteralNewlines — same requirement for JSONML.toString().
mvn test
Tests run: 827, Failures: 0, Errors: 0, Skipped: 6
The existing #1059/#1070 regression tests (testValidWhitespaceNumericEntityUnescape, testValidWhitespaceNumericEntityToJSONObject) still pass.;
Headings (most frequently used words):
uh, oh, navigation, fix, tab, lf, cr, escape, when, serializing, to, xml, 1093, footer, diff, view, menu, repository, there, are, no, files, selected, for, viewing, filter, by, extension,
Text of the page (most frequently used words):
xml (37), the (34), and (26), file (25), this (20), characters (20), java (20), github (16), code (16), tab (16), org (15), for (14), character (14), that (12), while (12), line (12), string (12), applied (11), escape (10), test (10), static (10), unicode (10), json (10), all (9), reload (9), jsonobject (9), new (9), are (9), numeric (9), junit (9), show (9), hidden (9), expand (8), xmloutput (8), literal (8), original (8), when (8), name (8), diff (8), return (8), you (7), suggestion (7), cannot (7), suggestions (7), must (7), changes (7), loading (7), contains (7), tostring (7), value (7), tojsonobject (7), references (7), serializing (7), open (7), src (7), sign (7), can (6), change (6), valid (6), public (6), whitespace (6), import (6), assert (6), number (6), bidirectional (6), about (6), see (6), not (5), security (5), please (5), comments (5), from (5), commit (5), there (5), asserttrue (5), void (5), tabxml (5), jsonexception (5), class (5), what (5), learn (5), view (5), int (5), isvalidxmlcharacter (5), with (5), main (5), fix (5), point (5), your (5), pull (4), was (4), error (4), page (4), down (4), jsonml (4), should (4), got (4), text (4), reference (4), joe (4), tester (4), assertthrows (4), range (4), control (4), review (4), more (4), mustescape (4), isisocontrol (4), 1093 (4), true (4), files (4), stleary (4), support (4), copilot (4), community (3), navigation (3), 2026 (3), back (3), request (3), has (3), add (3), batch (3), only (3), retry (3), lettuce (3), ntomato (3), survive (3), round (3), put (3), tests (3), generated (3), these (3), 1092 (3), serialization (3), parsing (3), rejected (3), may (3), interpreted (3), compiled (3), differently (3), than (3), appears (3), below (3), editor (3), reveals (3), desktop (3), delete (3), edit (3), xmltest (3), additions (3), 1059 (3), xmltokener (3), 0x9 (3), 0xa (3), 0xd (3), them (3), x20 (3), xd7ff (3), hide (3), filter (3), lyin (3), ottf (3), commits (3), merged (3), account (3), quality (3), another (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), build (3), contact (2), status (2), privacy (2), terms (2), footer (2), lines (2), single (2), one (2), per (2), viewing (2), invalid (2), toggle (2), preserve (2), same (2), escaping (2), reparsed (2), assertequals (2), trip (2), read (2), tabjo (2), parsers (2), would (2), subject (2), normalization (2), conforming (2), occurrences (2), parser (2), still (2), work (2), 133 (2), always (2), x7f (2), x9f (2), inside (2), but (2), deletions (2), here (2), path (2), charat (2), 167 (2), 0x10000 (2), 0x10ffff (2), 0xe000 (2), 0xfffd (2), 0x20 (2), 0xd7ff (2), xe000 (2), xfffd (2), x10000 (2), x10ffff (2), iso (2), out (2), boolean (2), written (2), param (2), 156 (2), selected (2), apply (2), split (2), unified (2), failed (2), load (2), jump (2), extension (2), oct (2), tree (2), issue (2), insights (2), projects (2), actions (2), repository (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, inc, right, now, check, later, queued, merge, multi, pending, reviews, been, marked, resolved, outdated, existing, order, create, applying, deleted, supported, subset, closed, because, were, made, annotations, notes, oops, something, went, wrong, tagname, mytag, testjsonmltostringescapesliteralnewlines, requirement, getstring, tmustard, testwhitespacecontrolcharsroundtripthroughxml, produced, trips, likewise, node, testescapesliteralwhitespacecontrolcharsonserialization, regression, where, 1070, stopped, lost, instead, writes, containing, does, accept, 159, 127, neighbouring, boundary, codepoints, behave, way, testrejectsc1controlcharacterreference, accepts, nel, x85, fixing, library, refused, those, char, 1610, 1611, testvalidwhitespacenumericentitytojsonobject, fail, assertnotequals, assertfalse, throw, substring, keep, being, accepted, also, escapes, validate, parsedecimalentity, parsehexentity, unescapeentity, throws, deletion, previous, release, accepting, separate, behaviour, keeps, parse, result, identical, keeping, therefore, legal, fall, reject, illegal, previously, omitted, causing, unescape, etc, w3c, spec, except, tabs, 0x1f, 0x7f, 0x9f, any, excluding, surrogate, blocks, fffe, ffff, https, www, rec, charsets, document, found, validated, method, they, includes, every, escaped, conversations, clear, filters, viewed, type, nbsp, again, fea3a2c, select, changed, checks, conversation, into, serialize, master, already, clicking, agree, our, occasionally, send, related, emails, statement, service, free, its, maintainers, have, question, project, items, wiki, requests, issues, message, dismiss, alert, switched, accounts, appearance, settings, search, pricing, event, talks, workshops, next, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, small, medium, teams, enterprises, stage, businesses, source, latest, improvements, across, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, analysis, enforcement, automation, ship, coding, agent, tasks, automated, hosting, collaboration, platform, menu, skip, content,
|