Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter: Character reference "&#x1B" is an invalid XML character. #43

Open
tazik561 opened this issue Jan 9, 2023 · 8 comments
Open

Comments

@tazik561
Copy link

tazik561 commented Jan 9, 2023

On my flutter project by using junitreport I am making junit report but it is XML,

 flutter test --machine | tojunit --output test.xml

Now by Ant, I want to make Html from it. test.xml is at the root of my project, here I made build.xml:

<project name="genTestReport" default="gen" basedir=".">
  <description>
    Generate the HTML report from JUnit XML files
  </description>

  <target name="gen">
    <property name="genReportDir" location="${basedir}/unitTestReports"/>
    <delete dir="${genReportDir}"/>
    <mkdir dir="${genReportDir}"/>
    <junitreport todir="${basedir}/unitTestReports">
      <fileset dir="${basedir}">
        <include name="test.xml"/>
      </fileset>
      <report format="frames" todir="${genReportDir}/html"/>
    </junitreport>
  </target>
</project>

Now I run this command in root folder:

alt@Alis-MBP rr-front % ant -buildfile build.xml
Buildfile: /Users/alt/Projects/rr-front/build.xml

gen:
   [delete] Deleting directory /Users/alt/Projects/rr-front/unitTestReports
    [mkdir] Created dir: /Users/alt/Projects/rr-front/unitTestReports
[junitreport] [Fatal Error] test.xml:264:23: Character reference "&#x1B" is an invalid XML character.
[junitreport] The file /Users/alt/Projects/rr-front/test.xml is not a valid XML document. It is possibly corrupted.

Does it seem I need some configuration ?

Inside test.xml I have some testcase like below:

<testcase 
classname=".Users.alt.Projects.rr_front.test.widgets.top3_pro.pro_container" name="overlay tap tap work" time="0.312">
      <system-out>&#x1B;[34m[🌎 Easy Localization] [WARNING] Localization key [widgets.pro_container.selected_a_pro] not found&#x1B;[0m</system-out>
@rspilker
Copy link
Contributor

rspilker commented Jan 9, 2023

Can you test what happens if you manually change the first line in the xml document to version="1.1"?

@tazik561
Copy link
Author

tazik561 commented Jan 9, 2023

Can you test what happens if you manually change the first line in the xml document to version="1.1"?

I changed and it seems Character reference "&#x1B" is an invalid XML character problem has gone,

<?xml version="1.1" encoding="UTF-8"?>
<testsuites>...

but I have this error:

gen:
   [delete] Deleting directory /Users/alt/Projects/rr-front/unitTestReports
    [mkdir] Created dir: /Users/alt/Projects/rr-front/unitTestReports
[junitreport] the file /Users/alt/Projects/rr-front/test.xml is not a valid testsuite XML document
[junitreport] Processing/Users/alt/Projects/rr-front/unitTestReports/TESTS-TestSuites.xml to /var/folders/t0/4hlhr8115vs6d6v9zz701dl40000gn/T/null977921457
[junitreport] Loading stylesheet jar:file:/opt/homebrew/Cellar/ant/1.10.12/libexec/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 212ms
[junitreport] Deleting: /var/folders/t0/4hlhr8115vs6d6v9zz701dl40000gn/T/null977921457

BUILD SUCCESSFUL
Total time: 0 seconds

error -> test.xml is not a valid testsuite XML document

@rspilker
Copy link
Contributor

rspilker commented Jan 9, 2023

Hmm, possibly the character problem disappeared because the ant junit task doesn't allow version 1.1 files at all.

Can you modify any working test suite xml to 1.1 to see if those then also break?

@tazik561
Copy link
Author

tazik561 commented Jan 10, 2023

I changed like this:

  <testsuite version="1.1" errors="0" failures="0" tests="2" skipped="0" name=".Users/alt/Projects/rr-front.test.utils.dart_trace" timestamp="2023-01-09T18:59:56">
    <properties>
      <property name="platform" value="vm"/>
    </properties>
    <testcase classname=".Users/alt/Projects/rr-front.test.utils.dart_trace" name="dart_trace parseDartTrace: should return an original stack trace" time="0.011"/>
    <testcase classname=".Users/alt/Projects/rr-front.test.utils.dart_trace" name="dart_trace parseDartTrace: should return a stack trace from the source map file" time="0.033"/>
  </testsuite>

No difference, I still have a not a valid testsuite XML document error.

@lukaszdudek-trueenergy
Copy link

lukaszdudek-trueenergy commented Sep 6, 2023

I have the same issue with GitLab CI XML parser - which doesn't support XML version 1.1:

JUnit XML parsing failed: 129:25: FATAL: xmlParseCharRef: invalid xmlChar value 27 

When I changed the version manually, it just says:

JUnit XML parsing failed: 1:20: WARNING: Unsupported version '1.1' 

Can you help me with this?

@nikitenich
Copy link

@lukaszdudek-trueenergy As a temporary solution you can remove unsupported char sequence from generated XML file at GitLab CI level.
For example:

script:
  - flutter test --machine --coverage ${TEST_DIR} | tojunit --output ${OUTPUT_XML_NAME}
  - sed -i 's/&#x1B;//g' ${OUTPUT_XML_NAME}

Where &#x1B; is char sequence that broke XML structure.

@SMCCZ
Copy link

SMCCZ commented Nov 27, 2023

Having similar issue while generating JSON report. Trying to generate test report with github action got Error: Invalid JSON at v1.0.22.json:5. Then tried locally it's generating an invalid JSON output. How to overcome the issue

@Holofox
Copy link

Holofox commented Jul 30, 2024

The flutter test command exited prematurely, so the file with invalid characters was still uploaded to the artifacts in Gitlab CI/CD. In my case, the following helped:

variables:
   J_UNIT_REPORT_FILE_NAME: junit-report.xml
script:
   - flutter test --machine --coverage | sed 's/\\u001b//g' | tojunit --output $J_UNIT_REPORT_FILE_NAME

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

No branches or pull requests

6 participants