Uploaded image for project: 'SwitchYard'
  1. SwitchYard
  2. SWITCHYARD-2660

XmlValidator converts String contents to platform default encoding, causes data corruption

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1.1
    • Component/s: core
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      1. Put some non-ASCII character to the input for XmlValidatorTest/test_valid_xml

      diff --git a/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java b/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java
      index 4e406b0..09e5fc5 100644
      --- a/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java
      +++ b/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java
      @@ -67,7 +67,7 @@ public class XmlValidatorTest extends AbstractValidatorTestCase {
               if (!result.isValid()) {
                   Assert.fail(result.getDetail());
               }
      -        source = "<person2 firstName='foo' lastName='bar' age='50' />";
      +        source = "<person2 firstName='タロウ' lastName='ヤマダ' age='50' />";
               result = validator.validate(new DefaultMessage().setContent(source));
               if (!result.isValid()) {
                   Assert.fail(result.getDetail());
      

      2. Change platform default encoding for the testcase

      diff --git a/validate/pom.xml b/validate/pom.xml
      index 7669262..b57f0d1 100644
      --- a/validate/pom.xml
      +++ b/validate/pom.xml
      @@ -91,4 +91,15 @@
                   <artifactId>jackson-core-asl</artifactId>
               </dependency>
           </dependencies>
      +    <build>
      +        <plugins>
      +            <plugin>
      +                <groupId>org.apache.maven.plugins</groupId>
      +                <artifactId>maven-surefire-plugin</artifactId>
      +                <configuration>
      +                    <argLine>-Dfile.encoding=EUC_JP</argLine>
      +                </configuration>
      +            </plugin>
      +        </plugins>
      +    </build>
       </project>
      
      Show
      1. Put some non-ASCII character to the input for XmlValidatorTest/test_valid_xml diff --git a/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java b/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java index 4e406b0..09e5fc5 100644 --- a/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java +++ b/validate/src/test/java/org/switchyard/validate/internal/xml/XmlValidatorTest.java @@ -67,7 +67,7 @@ public class XmlValidatorTest extends AbstractValidatorTestCase { if (!result.isValid()) { Assert.fail(result.getDetail()); } - source = "<person2 firstName= 'foo' lastName= 'bar' age= '50' />" ; + source = "<person2 firstName= 'タロウ' lastName= 'ヤマダ' age= '50' />" ; result = validator.validate( new DefaultMessage().setContent(source)); if (!result.isValid()) { Assert.fail(result.getDetail()); 2. Change platform default encoding for the testcase diff --git a/validate/pom.xml b/validate/pom.xml index 7669262..b57f0d1 100644 --- a/validate/pom.xml +++ b/validate/pom.xml @@ -91,4 +91,15 @@ <artifactId>jackson-core-asl</artifactId> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-Dfile.encoding=EUC_JP</argLine> + </configuration> + </plugin> + </plugins> + </build> </project>

      Description

      XmlValidator is using java.lang.String.getBytes() to get the byte array for the contents, which converts to platform default encoding. If the platform default is not a UTF8, validation fails since the parser assumes UTF8.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  igarashitm tomohisa igarashi
                  Reporter:
                  igarashitm tomohisa igarashi
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: