Skip to content

[FIX] xml-double-quotes-py: Properly extract multiline tag content in NodeContent#187

Closed
moylop260 wants to merge 1 commit intoOCA:mainfrom
vauxoo-dev:fix-double-quotes-moy
Closed

[FIX] xml-double-quotes-py: Properly extract multiline tag content in NodeContent#187
moylop260 wants to merge 1 commit intoOCA:mainfrom
vauxoo-dev:fix-double-quotes-moy

Conversation

@moylop260
Copy link
Copy Markdown
Collaborator

@moylop260 moylop260 commented Apr 28, 2026

Previously, NodeContent._read_node failed to identify the start of an XML tag if it was not placed at the very beginning of a line or if the tag spanned multiple lines. This caused hooks that relied on exact string representation (like xml-double-quotes-py) to miss cases where attributes with Python expressions contained escaped double quotes (").
This commit improves the tag search logic by:
- Using a robust regular expression to match the opening tag anywhere on the line.
- Searching backwards from the node's sourceline (which points to the end of the opening tag) up to the parent's starting line, ensuring the tag's true start is correctly located.
Additionally, this fix surfaces previously hidden xml-double-quotes-py errors, so the expected error count in test_checks.py was updated accordingly.

Using IA with Gemini

@moylop260 moylop260 self-assigned this Apr 28, 2026
@moylop260 moylop260 force-pushed the fix-double-quotes-moy branch 3 times, most recently from 52888f3 to 59bd26f Compare April 28, 2026 22:15
@moylop260 moylop260 changed the title [FIX] xml-double-quotes-py: Fix new case detected [FIX] xml-double-quotes-py: Properly extract multiline tag content in NodeContent Apr 28, 2026
@moylop260 moylop260 force-pushed the fix-double-quotes-moy branch from 59bd26f to e4ca580 Compare April 28, 2026 22:20
… NodeContent

Previously, `NodeContent._read_node` failed to identify the start of an XML tag if it was not placed at the very beginning of a line or if the tag spanned multiple lines. This caused hooks that relied on exact string representation (like `xml-double-quotes-py`) to miss cases where attributes with Python expressions contained escaped double quotes (`"`).
This commit improves the tag search logic by:
- Using a robust regular expression to match the opening tag anywhere on the line.
- Searching backwards from the node's `sourceline` (which points to the end of the opening tag) up to the parent's starting line, ensuring the tag's true start is correctly located.
Additionally, this fix surfaces previously hidden `xml-double-quotes-py` errors, so the expected error count in `test_checks.py` was updated accordingly.
- Adjust the number of line to the real node
@moylop260 moylop260 force-pushed the fix-double-quotes-moy branch from e4ca580 to aeddf8f Compare April 29, 2026 02:15
@moylop260
Copy link
Copy Markdown
Collaborator Author

Summary

Both PR #187 and PR #188 address the same issue: NodeContent._read_node fails to detect the start of an XML tag when the tag appears after other content on the same line or spans multiple lines, which leads to incorrect line numbers being reported by the xml-double-quotes-py check.

Why PR #188 is the preferred solution

Aspect PR #187 PR #188
Core change Adds a regular‑expression scan on the line of sourceline. Extends NodeContent to accept an optional XMLStartTagLocator and uses it as the single source of truth for tag start positions.
Use of existing infrastructure Re‑implements tag detection with a new regex. Re‑uses the already‑implemented, robust XMLStartTagLocator (which parses the whole file once).
Caching / performance No caching – the regex runs for each node. The locator is cached in _get_tag_locator (manifest_data["_tag_locator"]), avoiding repeated file scans.
Fallback safety Relies solely on the regex. Keeps a regex fallback for callers that don’t pass a locator, preserving compatibility.
Test coverage No new tests. Adds test_xml_double_quotes_py_reports_correct_line_for_inline_and_multiline_tags to guarantee correct line reporting for the corner cases.
Maintainability Logic is duplicated and fragile; future XML edge‑cases may break it again. Centralises position logic in XMLStartTagLocator, making future extensions easier and reducing duplication.
Documentation Minimal changes to the code base. Explicitly documents the new locator argument in NodeContent.__init__, making the API clear for future checks.

Conclusion

PR #188 provides a more robust, maintainable, and performant solution. It leverages the existing locator, adds proper caching, includes a regression test, and keeps a safe fallback. For these reasons, I recommend merging PR #188 and closing PR #187.

I am an AI assistant powered by GPT.

@moylop260 moylop260 closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant