mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-28 15:56:31 +00:00
Merge pull request #1522 from The-Lum/Dev
mod: Handle `@start/@end` syntax error better
This commit is contained in:
commit
9b761b7f92
@ -154,7 +154,7 @@ public class SourceStringReader {
|
|||||||
public DiagramDescription outputImage(OutputStream os, int numImage, FileFormatOption fileFormatOption)
|
public DiagramDescription outputImage(OutputStream os, int numImage, FileFormatOption fileFormatOption)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (blocks.size() == 0) {
|
if (blocks.size() == 0) {
|
||||||
noStartumlFound(os, fileFormatOption);
|
noValidStartFound(os, fileFormatOption);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (BlockUml b : blocks) {
|
for (BlockUml b : blocks) {
|
||||||
@ -230,8 +230,8 @@ public class SourceStringReader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageData noStartumlFound(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
|
public ImageData noValidStartFound(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
|
||||||
final TextBlock error = GraphicStrings.createForError(Arrays.asList("No @startuml/@enduml found"),
|
final TextBlock error = GraphicStrings.createForError(Arrays.asList("No valid @start/@end found, please check the version"),
|
||||||
fileFormatOption.isUseRedForError());
|
fileFormatOption.isUseRedForError());
|
||||||
|
|
||||||
return plainImageBuilder(error, fileFormatOption).write(os);
|
return plainImageBuilder(error, fileFormatOption).write(os);
|
||||||
|
@ -269,9 +269,9 @@ public class PicoWebServer implements Runnable {
|
|||||||
|
|
||||||
if (ssr.getBlocks().size() == 0) {
|
if (ssr.getBlocks().size() == 0) {
|
||||||
system = PSystemErrorUtils.buildV2(null,
|
system = PSystemErrorUtils.buildV2(null,
|
||||||
new ErrorUml(SYNTAX_ERROR, "No @startuml/@enduml found", 0, new LineLocationImpl("", null)), null,
|
new ErrorUml(SYNTAX_ERROR, "No valid @start/@end found, please check the version", 0, new LineLocationImpl("", null)), null,
|
||||||
Collections.<StringLocated>emptyList());
|
Collections.<StringLocated>emptyList());
|
||||||
imageData = ssr.noStartumlFound(os, option.getFileFormatOption());
|
imageData = ssr.noValidStartFound(os, option.getFileFormatOption());
|
||||||
} else {
|
} else {
|
||||||
system = ssr.getBlocks().get(0).getDiagram();
|
system = ssr.getBlocks().get(0).getDiagram();
|
||||||
imageData = system.exportDiagram(os, 0, option.getFileFormatOption());
|
imageData = system.exportDiagram(os, 0, option.getFileFormatOption());
|
||||||
|
@ -217,12 +217,15 @@ class PipeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = { "ab\nc", // *nix, macOsX
|
@ValueSource(strings = {
|
||||||
|
"ab\nc", // *nix, macOsX
|
||||||
"ab\rc", // pre-macOsX macs
|
"ab\rc", // pre-macOsX macs
|
||||||
"ab\r\nc", // Windows
|
"ab\r\nc", // Windows
|
||||||
// the case \n\r is handled as 2 new lines, thus not added
|
// the case \n\r is handled as 2 new lines, thus not added
|
||||||
|
"ab\nc\n",
|
||||||
"ab\nc\n", "ab\nc\r", "ab\nc\r\n" })
|
"ab\nc\r",
|
||||||
|
"ab\nc\r\n"
|
||||||
|
})
|
||||||
void should_readFirstDiagram_decode_correctly_different_line_endings(String input) throws IOException {
|
void should_readFirstDiagram_decode_correctly_different_line_endings(String input) throws IOException {
|
||||||
pipe = new Pipe(option, null, new ByteArrayInputStream(input.getBytes(UTF_8)), UTF_8.name());
|
pipe = new Pipe(option, null, new ByteArrayInputStream(input.getBytes(UTF_8)), UTF_8.name());
|
||||||
|
|
||||||
@ -247,6 +250,14 @@ class PipeTest {
|
|||||||
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\n",
|
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\n",
|
||||||
"@startuml\nab\ncde\n@enduml\n"));
|
"@startuml\nab\ncde\n@enduml\n"));
|
||||||
l.add(InputExpected.of("@startwhatever\nab\rcde\n@endwhatever", "@startwhatever\nab\ncde\n@endwhatever\n"));
|
l.add(InputExpected.of("@startwhatever\nab\rcde\n@endwhatever", "@startwhatever\nab\ncde\n@endwhatever\n"));
|
||||||
|
l.add(InputExpected.of("@start\nab\rcde\n@end", "@start\nab\ncde\n@end\n"));
|
||||||
|
// TODO: fix `readSingleDiagram` to allow @startX/@endX, the corresponding test is here:
|
||||||
|
// l.add(InputExpected.of("@startX\nab\rcde\n@endX", "@startX\nab\ncde\n@endX\n"));
|
||||||
|
l.add(InputExpected.of("@startXY\nab\rcde\n@endXY", "@startXY\nab\ncde\n@endXY\n"));
|
||||||
|
l.add(InputExpected.of("@startXYZ\nab\rcde\n@endXYZ", "@startXYZ\nab\ncde\n@endXYZ\n"));
|
||||||
|
l.add(InputExpected.of("@start1\nab\rcde\n@end1", "@start1\nab\ncde\n@end1\n"));
|
||||||
|
l.add(InputExpected.of("@start12\nab\rcde\n@end12", "@start12\nab\ncde\n@end12\n"));
|
||||||
|
l.add(InputExpected.of("@start123\nab\rcde\n@end123", "@start123\nab\ncde\n@end123\n"));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +285,14 @@ class PipeTest {
|
|||||||
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\n",
|
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\n",
|
||||||
"@startuml\nab\ncde\n@enduml\n"));
|
"@startuml\nab\ncde\n@enduml\n"));
|
||||||
l.add(InputExpected.of("@startwhatever\nab\rcde\n@endwhatever", "@startwhatever\nab\ncde\n@endwhatever\n"));
|
l.add(InputExpected.of("@startwhatever\nab\rcde\n@endwhatever", "@startwhatever\nab\ncde\n@endwhatever\n"));
|
||||||
|
l.add(InputExpected.of("@start\nab\rcde\n@end", "@start\nab\ncde\n@end\n"));
|
||||||
|
// TODO: fix `readSingleDiagram` to allow @startX/@endX, the corresponding test is here:
|
||||||
|
// l.add(InputExpected.of("@startX\nab\rcde\n@endX", "@startX\nab\ncde\n@endX\n"));
|
||||||
|
l.add(InputExpected.of("@startXY\nab\rcde\n@endXY", "@startXY\nab\ncde\n@endXY\n"));
|
||||||
|
l.add(InputExpected.of("@startXYZ\nab\rcde\n@endXYZ", "@startXYZ\nab\ncde\n@endXYZ\n"));
|
||||||
|
l.add(InputExpected.of("@start1\nab\rcde\n@end1", "@start1\nab\ncde\n@end1\n"));
|
||||||
|
l.add(InputExpected.of("@start12\nab\rcde\n@end12", "@start12\nab\ncde\n@end12\n"));
|
||||||
|
l.add(InputExpected.of("@start123\nab\rcde\n@end123", "@start123\nab\ncde\n@end123\n"));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,13 +197,13 @@ public class PicoWebServerTest {
|
|||||||
|
|
||||||
response = httpPostJson("/render", renderRequestJson("@startuml", "-ttxt"));
|
response = httpPostJson("/render", renderRequestJson("@startuml", "-ttxt"));
|
||||||
assert response.getResponseCode() == 200;
|
assert response.getResponseCode() == 200;
|
||||||
assert response.getHeaderField("X-PlantUML-Diagram-Error").equals("No @startuml/@enduml found");
|
assert response.getHeaderField("X-PlantUML-Diagram-Error").equals("No valid @start/@end found, please check the version");
|
||||||
assert response.getHeaderField("X-PlantUML-Diagram-Error-Line").equals("0");
|
assert response.getHeaderField("X-PlantUML-Diagram-Error-Line").equals("0");
|
||||||
assert response.getContentType().equals("text/plain");
|
assert response.getContentType().equals("text/plain");
|
||||||
assert readStreamAsString(response.getInputStream()).equals("" +
|
assert readStreamAsString(response.getInputStream()).equals("" +
|
||||||
" \n" +
|
" \n" +
|
||||||
" \n" +
|
" \n" +
|
||||||
" No @startuml/@enduml found\n"
|
" No valid @start/@end found, please check the version\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
response = httpPostJson("/render", "");
|
response = httpPostJson("/render", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user