-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure that empty CDATA is properly parsed
There is a bug in the default Java XML Stream Reader in which an empty CDATA throws an IndexOutOfBoundsException when the schema is being validated. Therefore, we are creating our own delegating FlowableXMLStreamReader and handle the edge case for an empty CDATA.
- Loading branch information
Showing
11 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ble-bpmn-converter/src/main/java/org/flowable/bpmn/converter/FlowableXMLStreamReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flowable.bpmn.converter; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamReader; | ||
import javax.xml.stream.util.StreamReaderDelegate; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class FlowableXMLStreamReader extends StreamReaderDelegate { | ||
|
||
public FlowableXMLStreamReader(XMLStreamReader reader) { | ||
super(reader); | ||
} | ||
|
||
@Override | ||
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException { | ||
try { | ||
return super.getTextCharacters(sourceStart, target, targetStart, length); | ||
} catch (IndexOutOfBoundsException e) { | ||
if (length == 0) { | ||
// The default java stream reader has a bug where an empty CDATA will throw an IndexOutOfBoundsException | ||
// When the length to copy is 0, then we should not copy anything and just return 0 | ||
return 0; | ||
} | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ble-cmmn-converter/src/main/java/org/flowable/cmmn/converter/FlowableXMLStreamReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flowable.cmmn.converter; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamReader; | ||
import javax.xml.stream.util.StreamReaderDelegate; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class FlowableXMLStreamReader extends StreamReaderDelegate { | ||
|
||
public FlowableXMLStreamReader(XMLStreamReader reader) { | ||
super(reader); | ||
} | ||
|
||
@Override | ||
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException { | ||
try { | ||
return super.getTextCharacters(sourceStart, target, targetStart, length); | ||
} catch (IndexOutOfBoundsException e) { | ||
if (length == 0) { | ||
// The default java stream reader has a bug where an empty CDATA will throw an IndexOutOfBoundsException | ||
// When the length to copy is 0, then we should not copy anything and just return 0 | ||
return 0; | ||
} | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...es/org/flowable/cmmn/test/repository/DeploymentTest.testCaseDefinitionWithEmptyCDATA.cmmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions | ||
xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" | ||
xmlns:flowable="http://flowable.org/cmmn" | ||
targetNamespace="http://flowable.org/cmmn"> | ||
|
||
<case id="myCase" name="My Invalid Case Model"> | ||
<casePlanModel id="myPlanModel" name="My CasePlanModel"> | ||
<planItem id="planItem1" name="Task 1" definitionRef="CasePageTask_1"/> | ||
<task id="CasePageTask_1" name="Case page" flowable:type="casePage"> | ||
<extensionElements> | ||
<flowable:translation key="label" locale="it_it"><![CDATA[]]></flowable:translation> | ||
</extensionElements> | ||
</task> | ||
</casePlanModel> | ||
</case> | ||
|
||
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...flowable/engine/test/bpmn/deployment/BpmnDeploymentTest.testBpmnWithEmptyCDATA.bpmn20.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions id="definitions" | ||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | ||
xmlns:flowable="http://flowable.org/bpmn" | ||
targetNamespace="Examples"> | ||
|
||
<process id="myProcess"> | ||
|
||
<startEvent id="start" /> | ||
|
||
<sequenceFlow id="flow1" sourceRef="start" targetRef="end" > | ||
<extensionElements> | ||
<flowable:translation key="label" locale="it_it"><![CDATA[]]></flowable:translation> | ||
</extensionElements> | ||
</sequenceFlow> | ||
|
||
<endEvent id="end" /> | ||
|
||
</process> | ||
|
||
</definitions> |