refactor: build clip XML via XElement instead of string interpolation#222
Merged
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.
Summary
Replaces nine string-interpolated XML construction sites with
XElement/XAttribute/XCDataAPI calls. The framework handles attribute escaping and CDATA wrapping; manual escaping is no longer needed.Why
TableClipStrategy.DefaultXmlpreviously interpolated a clip name into an XML attribute via$"<BaseTable name=\"{clipName}\">". A clip namedMy "favorite" stuffproduced malformed XML; a recent fix patched the symptom by calling a hand-rolledXmlHelpers.XmlEscapebefore interpolation. Auditing for the same anti-pattern surfaced eight more sites:Calculation.ToXmland sevenXElement.Parse($"<X><![CDATA[{userText}]]></X>")callsites inFmField.ToXml. All share the same root cause — building structured XML by string concatenation — and the same class of edge-case failure (e.g.]]>inside calc text would terminate the CDATA early and throw on parse).Scope
TableClipStrategy.DefaultXml→new XElement("BaseTable", new XAttribute("name", clipName))Calculation.ToXml→new XElement(name, new XCData(Text))FmField.ToXml(×7: Calculation, ConstantData, MinimumValue, MaximumValue, StrictValidation, ErrorMessage, AutoEnter-Calculation) → sameXCDatapatternXmlHelpers.XmlEscapedeleted (no callers remain)IClipTypeStrategy.DefaultXmldoc-comment updated to point atXElementrather than at a manual-escape helpernew XCData(text)still can't legally hold the literal sequence]]>— that's an XML spec limitation, not an API one. The failure mode improves from "silent on-disk corruption" to "throw on save," which is acceptable; FileMaker's own calc grammar can't produce]]>either.Tests
All 1424 existing tests still pass. Added 3 new
Calculation.RoundTrip_PreservesXmlMetacharacterscases covering<,&,",'in calc text. Added oneO'BrienTheory row toTable_DefaultXml_EscapesPunctuationInName.Follow-up
The display-text path uses a different escape contract (FileMaker's own quoting convention rather than XML escaping) and is tracked separately in #221 — script/layout/menu-set names containing
"produce ambiguous display text. Round-trip probably still works via greedy regex but isn't covered by tests; lower priority than this fix.