Skip to content

Commit 38ed6d0

Browse files
authored
Fix issue regarding xmls with missing xml tag not parsing well (#10)
* Fix issue regarding xmls with missing xml tag not parsing well * Fix codestyle * Change ci github action ubuntu runner to latest
1 parent 51dc735 commit 38ed6d0

File tree

7 files changed

+144
-5
lines changed

7 files changed

+144
-5
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
1414

.github/workflows/codestyle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
1414

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
1313

.github/workflows/spotbugs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
1414

src/main/java/io/github/easybill/Services/XMLSanitizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class XMLSanitizer {
4444
) {
4545
var indexOfXmlIntro = payload.indexOf("<?xml version");
4646

47-
if (indexOfXmlIntro == 0) {
47+
if (indexOfXmlIntro == 0 || indexOfXmlIntro == -1) {
4848
return payload;
4949
}
5050

src/test/java/io/github/easybill/ValidationControllerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ void testValidationEndpointWithPayloadIncludingBOM() throws IOException {
6767
.body("errors", empty());
6868
}
6969

70+
@Test
71+
// The XML tag (i. e. <?xml) is optional. So we should be able to parse the xml even if it is missing the tag
72+
void testValidationEndpointWithPayloadMissingTheXmlTag()
73+
throws IOException {
74+
given()
75+
.body(loadFixtureFileAsStream("UBL/xrechnung-missing-xml-tag.xml"))
76+
.contentType(ContentType.XML)
77+
.when()
78+
.post("/validation")
79+
.then()
80+
.statusCode(200)
81+
.contentType(ContentType.JSON)
82+
.body("is_valid", equalTo(true))
83+
.body("errors", empty());
84+
}
85+
7086
@Test
7187
void testValidationEndpointWithPayloadIncludingCharsInProlog()
7288
throws IOException {
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
2+
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
3+
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
4+
<cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0</cbc:CustomizationID>
5+
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
6+
<cbc:ID>202505/07277</cbc:ID>
7+
<cbc:IssueDate>2025-05-08</cbc:IssueDate>
8+
<cbc:DueDate>2025-05-15</cbc:DueDate>
9+
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
10+
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
11+
<cbc:BuyerReference>50258002</cbc:BuyerReference>
12+
<cac:AccountingSupplierParty>
13+
<cac:Party>
14+
<cbc:EndpointID schemeID="EM">service@it-fachmann.de</cbc:EndpointID>
15+
<cac:PartyName>
16+
<cbc:Name>Muster IT-Fachmann</cbc:Name>
17+
</cac:PartyName>
18+
<cac:PostalAddress>
19+
<cbc:StreetName>Musterstr. 123</cbc:StreetName>
20+
<cbc:CityName>Bielefeld</cbc:CityName>
21+
<cbc:PostalZone>12345</cbc:PostalZone>
22+
<cac:Country>
23+
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
24+
</cac:Country>
25+
</cac:PostalAddress>
26+
<cac:PartyTaxScheme>
27+
<cbc:CompanyID>DE123456789</cbc:CompanyID>
28+
<cac:TaxScheme>
29+
<cbc:ID>VAT</cbc:ID>
30+
</cac:TaxScheme>
31+
</cac:PartyTaxScheme>
32+
<cac:PartyLegalEntity>
33+
<cbc:RegistrationName>Muster IT-Fachmann</cbc:RegistrationName>
34+
</cac:PartyLegalEntity>
35+
<cac:Contact>
36+
<cbc:Name>Muster IT-Fachmann</cbc:Name>
37+
<cbc:Telephone>+49 12345 123456</cbc:Telephone>
38+
<cbc:ElectronicMail>service@it-fachmann.de</cbc:ElectronicMail>
39+
</cac:Contact>
40+
</cac:Party>
41+
</cac:AccountingSupplierParty>
42+
<cac:AccountingCustomerParty>
43+
<cac:Party>
44+
<cbc:EndpointID schemeID="EM">invoice@empfaenger.de</cbc:EndpointID>
45+
<cac:PartyIdentification>
46+
<cbc:ID>50258002</cbc:ID>
47+
</cac:PartyIdentification>
48+
<cac:PartyName>
49+
<cbc:Name>Mustermann GmbH</cbc:Name>
50+
</cac:PartyName>
51+
<cac:PostalAddress>
52+
<cbc:StreetName>Musterstr. 123</cbc:StreetName>
53+
<cbc:CityName>Frankfurt</cbc:CityName>
54+
<cbc:PostalZone>60329</cbc:PostalZone>
55+
<cac:Country>
56+
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
57+
</cac:Country>
58+
</cac:PostalAddress>
59+
<cac:PartyLegalEntity>
60+
<cbc:RegistrationName>Mustermann GmbH</cbc:RegistrationName>
61+
</cac:PartyLegalEntity>
62+
<cac:Contact>
63+
<cbc:ElectronicMail>invoice@empfaenger.de</cbc:ElectronicMail>
64+
</cac:Contact>
65+
</cac:Party>
66+
</cac:AccountingCustomerParty>
67+
<cac:PaymentMeans>
68+
<cbc:PaymentMeansCode>30</cbc:PaymentMeansCode>
69+
<cbc:PaymentID>202505/07277</cbc:PaymentID>
70+
<cac:PayeeFinancialAccount>
71+
<cbc:ID>DE02500105170137075030</cbc:ID>
72+
<cbc:Name>Muster IT-Fachmann</cbc:Name>
73+
<cac:FinancialInstitutionBranch>
74+
<cbc:ID>BYLADEM1001</cbc:ID>
75+
</cac:FinancialInstitutionBranch>
76+
</cac:PayeeFinancialAccount>
77+
</cac:PaymentMeans>
78+
<cac:TaxTotal>
79+
<cbc:TaxAmount currencyID="EUR">56.81</cbc:TaxAmount>
80+
<cac:TaxSubtotal>
81+
<cbc:TaxableAmount currencyID="EUR">299.00</cbc:TaxableAmount>
82+
<cbc:TaxAmount currencyID="EUR">56.81</cbc:TaxAmount>
83+
<cac:TaxCategory>
84+
<cbc:ID>S</cbc:ID>
85+
<cbc:Percent>19</cbc:Percent>
86+
<cac:TaxScheme>
87+
<cbc:ID>VAT</cbc:ID>
88+
</cac:TaxScheme>
89+
</cac:TaxCategory>
90+
</cac:TaxSubtotal>
91+
</cac:TaxTotal>
92+
<cac:LegalMonetaryTotal>
93+
<cbc:LineExtensionAmount currencyID="EUR">299.00</cbc:LineExtensionAmount>
94+
<cbc:TaxExclusiveAmount currencyID="EUR">299.00</cbc:TaxExclusiveAmount>
95+
<cbc:TaxInclusiveAmount currencyID="EUR">355.81</cbc:TaxInclusiveAmount>
96+
<cbc:PayableAmount currencyID="EUR">355.81</cbc:PayableAmount>
97+
</cac:LegalMonetaryTotal>
98+
<cac:InvoiceLine>
99+
<cbc:ID>1</cbc:ID>
100+
<cbc:InvoicedQuantity unitCode="EA">1</cbc:InvoicedQuantity>
101+
<cbc:LineExtensionAmount currencyID="EUR">299.00</cbc:LineExtensionAmount>
102+
<cac:Item>
103+
<cbc:Description>Example item
104+
105+
Liefertermin: 08.05.2025
106+
</cbc:Description>
107+
<cbc:Name>SW:Backup</cbc:Name>
108+
<cac:SellersItemIdentification>
109+
<cbc:ID>900001</cbc:ID>
110+
</cac:SellersItemIdentification>
111+
<cac:ClassifiedTaxCategory>
112+
<cbc:ID>S</cbc:ID>
113+
<cbc:Percent>19</cbc:Percent>
114+
<cac:TaxScheme>
115+
<cbc:ID>VAT</cbc:ID>
116+
</cac:TaxScheme>
117+
</cac:ClassifiedTaxCategory>
118+
</cac:Item>
119+
<cac:Price>
120+
<cbc:PriceAmount currencyID="EUR">299</cbc:PriceAmount>
121+
</cac:Price>
122+
</cac:InvoiceLine>
123+
</Invoice>

0 commit comments

Comments
 (0)