Skip to content

Commit

Permalink
fix schemaVersion regex not matching for complete attribute value
Browse files Browse the repository at this point in the history
  • Loading branch information
sboeckelmann committed Oct 31, 2023
1 parent 1fed64c commit 559f2ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class AttributePreScanUtil {

private static final String SCHEMA_VERSION_REGEX ="schemaVersion\"?'?\\s*[=:]\\s*([\"'])?([^\"']*)";
private static final String SCHEMA_VERSION_REGEX ="schemaVersion\"?'?\\s*[=:]\\s*([\"'])?([^\"']*)[\"?'?]";
private static final Pattern SCHEMA_VERSION_PATTERN = Pattern.compile(SCHEMA_VERSION_REGEX);
private static final int READ_LIMIT = 4096;
public static final String scanSchemaVersion(final BufferedInputStream input) throws IOException {
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/io/openepcis/version/VersionDetectorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.io.openepcis.version;

import io.openepcis.constants.EPCISVersion;
import io.openepcis.convert.VersionTransformer;
import io.openepcis.resources.util.Commons;
import jakarta.xml.bind.JAXBException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.BufferedInputStream;
import java.io.IOException;

public class VersionDetectorTest {
private final VersionTransformer versionTransformer;

public VersionDetectorTest() throws JAXBException {
versionTransformer = new VersionTransformer();
}

@Test
void testJSON_2_0_0() throws IOException {
final EPCISVersion version = versionTransformer.versionDetector(new BufferedInputStream(Commons.getInputStream("2.0/EPCIS/JSON/Capture/Documents/Combination_of_different_event.json")));
Assertions.assertEquals(EPCISVersion.VERSION_2_0_0, version);
}

@Test
void testXML_2_0_0() throws IOException {
final EPCISVersion version = versionTransformer.versionDetector(new BufferedInputStream(Commons.getInputStream("2.0/EPCIS/XML/Capture/Documents/Combination_of_different_event.xml")));
Assertions.assertEquals(EPCISVersion.VERSION_2_0_0, version);
}

@Test
void testXML_1_2_0() throws IOException {
final EPCISVersion version = versionTransformer.versionDetector(new BufferedInputStream(Commons.getInputStream("1.2/EPCIS/XML/Capture/Documents/ObjectEvent.xml")));
Assertions.assertEquals(EPCISVersion.VERSION_1_2_0, version);
}
// new String(Commons.getInputStream("2.0/EPCIS/JSON/Capture/Documents/Combination_of_different_event.json").readAllBytes(), StandardCharsets.UTF_8);
}

0 comments on commit 559f2ff

Please sign in to comment.