Skip to content

Fix panic formatting processing instructions without attributes#194

Merged
sibprogrammer merged 1 commit into
sibprogrammer:masterfrom
SAY-5:fix/procinst-panic
May 12, 2026
Merged

Fix panic formatting processing instructions without attributes#194
sibprogrammer merged 1 commit into
sibprogrammer:masterfrom
SAY-5:fix/procinst-panic

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 12, 2026

Problem

xq core-dumps when processing instructions other than <?xml ...?> have no pseudo-attributes (or any PI body lacking an =), e.g.:

$ { echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<?xml-stylesheet?>'; echo '<rss/>'; } | xq
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheetpanic: runtime error: index out of range [1] with length 1

Fixes #193.

Cause

In FormatXml, the xml.ProcInst branch split each pseudo-attribute on = and unconditionally read attrComponents[1]. An empty Inst (or one without =) yields a single-element slice, so the index panics.

Fix

Skip an empty PI body and only emit the =value part when the split actually produced two components.

Test plan

  • Added test/data/xml/unformatted17.xml / formatted17.xml covering <?xml-stylesheet?> and <?xml-stylesheet type="text/xsl" href="style.xsl"?>, wired into TestFormatXml.
  • go test ./... passes; the new case panics on master without this change.
  • go vet ./... and gofmt clean.

FormatXml indexed attrComponents[1] unconditionally when splitting a
processing instruction's pseudo-attributes on '=', causing an index out
of range panic for instructions like <?xml-stylesheet?> or any PI whose
body is empty or lacks an '=' separator.
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.73%. Comparing base (7c06848) to head (d688a1d).

Files with missing lines Patch % Lines
internal/utils/utils.go 75.00% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #194      +/-   ##
==========================================
- Coverage   80.90%   80.73%   -0.18%     
==========================================
  Files           5        5              
  Lines         707      711       +4     
==========================================
+ Hits          572      574       +2     
- Misses         93       94       +1     
- Partials       42       43       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sibprogrammer sibprogrammer merged commit a296a08 into sibprogrammer:master May 12, 2026
2 checks passed
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.

"<?xml-stylesheet […]?>" causes core dump

3 participants