[codex] Fix template expression parsing compatibility#200
Open
xsploit wants to merge 2 commits into
Open
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves POML template compatibility by preventing XML parsing failures caused by XML-sensitive characters in template expressions/content, and by decoding XML entities before expression evaluation. It also extends conditional templating support and adds a <tool-policy> component alias with regression tests.
Changes:
- Normalize POML input prior to XML parsing and unescape XML entities before evaluating template expressions / meta eval blocks.
- Expand template conditional support (XML-sensitive operators,
<if condition="...">wrapper, multiline{{ ... }}attribute expressions, missing-variable fallbacks). - Add
<tool-policy>component alias and regression tests covering the compatibility cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/poml/file.tsx | Normalizes XML input, unescapes entity text, extends if handling, updates expression evaluation semantics, and adds shared content processing helper. |
| packages/poml/components/instructions.tsx | Introduces ToolPolicy component with toolPolicy / tool-policy aliases. |
| packages/poml/tests/file.test.tsx | Adds regression tests for XML-sensitive operators/entities, <if condition>, missing-variable fallbacks, multiline attribute expressions, and <tool-policy>. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
135
to
138
| private readXml(text: string) { | ||
| text = normalizePomlXmlInput(text); | ||
| const { cst, tokenVector, lexErrors, parseErrors } = parseXML(text); | ||
| const errors: ReadError[] = []; |
| const ifElement = this.handleIfElement(element, globalContext, currentLocal); | ||
| if (ifElement !== undefined) { | ||
| if (ifElement) { | ||
| resultElements.push(ifElement); |
Author
|
Addressed the Copilot review comments in 39593a7:
Validation rerun:
|
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
<and&in text/attribute values no longer explode before template evaluation&&,<, and>ifguards, and<if condition="...">wrappers<tool-policy>component alias and regression coverage for the compatibility casesRoot Cause
POML templates are parsed as XML before template expressions are evaluated. That means common JavaScript expression characters such as
<and&can fail at the XML lexer layer, while XML entity escapes can survive into the JavaScript evaluator without being decoded. Separately, missing context variables throw before fallback expressions likemissing || "fallback"can work.This is related to #197, which reports
unexpected character: ->&<-while rendering a POML file.Validation
npm test -- --runInBand packages/poml/testsnpm run build-clipython -m pytest python/tests/test_poml_formats.py python/tests/test_basic.pynpx prettier --check packages/poml/file.tsx packages/poml/components/instructions.tsx packages/poml/tests/file.test.tsx