mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-25 04:06:08 +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)
|
||||
throws IOException {
|
||||
if (blocks.size() == 0) {
|
||||
noStartumlFound(os, fileFormatOption);
|
||||
noValidStartFound(os, fileFormatOption);
|
||||
return null;
|
||||
}
|
||||
for (BlockUml b : blocks) {
|
||||
@ -230,8 +230,8 @@ public class SourceStringReader {
|
||||
|
||||
}
|
||||
|
||||
public ImageData noStartumlFound(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
|
||||
final TextBlock error = GraphicStrings.createForError(Arrays.asList("No @startuml/@enduml found"),
|
||||
public ImageData noValidStartFound(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
|
||||
final TextBlock error = GraphicStrings.createForError(Arrays.asList("No valid @start/@end found, please check the version"),
|
||||
fileFormatOption.isUseRedForError());
|
||||
|
||||
return plainImageBuilder(error, fileFormatOption).write(os);
|
||||
|
@ -269,9 +269,9 @@ public class PicoWebServer implements Runnable {
|
||||
|
||||
if (ssr.getBlocks().size() == 0) {
|
||||
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());
|
||||
imageData = ssr.noStartumlFound(os, option.getFileFormatOption());
|
||||
imageData = ssr.noValidStartFound(os, option.getFileFormatOption());
|
||||
} else {
|
||||
system = ssr.getBlocks().get(0).getDiagram();
|
||||
imageData = system.exportDiagram(os, 0, option.getFileFormatOption());
|
||||
|
@ -217,12 +217,15 @@ class PipeTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "ab\nc", // *nix, macOsX
|
||||
@ValueSource(strings = {
|
||||
"ab\nc", // *nix, macOsX
|
||||
"ab\rc", // pre-macOsX macs
|
||||
"ab\r\nc", // Windows
|
||||
// the case \n\r is handled as 2 new lines, thus not added
|
||||
|
||||
"ab\nc\n", "ab\nc\r", "ab\nc\r\n" })
|
||||
"ab\nc\n",
|
||||
"ab\nc\r",
|
||||
"ab\nc\r\n"
|
||||
})
|
||||
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());
|
||||
|
||||
@ -247,6 +250,14 @@ class PipeTest {
|
||||
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\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("@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;
|
||||
}
|
||||
|
||||
@ -274,6 +285,14 @@ class PipeTest {
|
||||
l.add(InputExpected.of("this-is-garbage\n@startuml\nab\rcde\n@enduml\nthis-is-garbage\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("@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;
|
||||
}
|
||||
|
||||
|
@ -197,13 +197,13 @@ public class PicoWebServerTest {
|
||||
|
||||
response = httpPostJson("/render", renderRequestJson("@startuml", "-ttxt"));
|
||||
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.getContentType().equals("text/plain");
|
||||
assert readStreamAsString(response.getInputStream()).equals("" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
" No @startuml/@enduml found\n"
|
||||
" No valid @start/@end found, please check the version\n"
|
||||
);
|
||||
|
||||
response = httpPostJson("/render", "");
|
||||
|
Loading…
Reference in New Issue
Block a user