Allow the CR character as part of a newline.

Since CodeOcean may send the `\r\n` newline.
This commit is contained in:
Maximilian Paß
2022-04-18 15:43:36 +02:00
parent ba98916121
commit 430b1748f5
3 changed files with 28 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class SimpleMakefile {
private static final Pattern isMakeCommand = Pattern.compile("^make(?:\\s+(?<startRule>\\w*))?$");
// This pattern identifies the rules in a makefile.
private static final Pattern makeRules = Pattern.compile("(?<name>.*):\\n(?<commands>(?:\\t.+\\n?)*)");
private static final Pattern makeRules = Pattern.compile("(?<name>.*):\\r?\\n(?<commands>(?:\\t.+\\r?\\n?)*)");
// The first rule of the makefile.
private String firstRule = null;

View File

@ -22,6 +22,15 @@ public class SimpleMakefileTest {
"\techo Hi\n"
).getBytes(StandardCharsets.UTF_8));
static final String SuccessfulWindowsMakefile = Base64.getEncoder().encodeToString(
("run:\r\n" +
"\tjavac org/example/RecursiveMath.java\r\n" +
"\tjava org/example/RecursiveMath\r\n" +
"\r\n" +
"test:\r\n" +
"\techo Hi\r\n"
).getBytes(StandardCharsets.UTF_8));
static final String NotSupportedMakefile = Base64.getEncoder().encodeToString(
("run: test\n" +
"\tjavac org/example/RecursiveMath.java\n" +
@ -48,6 +57,23 @@ public class SimpleMakefileTest {
}
}
@Test
public void sucessfullMakeWithCR() {
Map<String, String> files = new HashMap<>();
files.put("Makefile", SuccessfulWindowsMakefile);
files.put("org/example/RecursiveMath.java", RecursiveMathContent);
try {
String command = "make run";
SimpleMakefile makefile = new SimpleMakefile(files);
String cmd = makefile.parseCommand(command);
assertEquals("javac org/example/RecursiveMath.java && java org/example/RecursiveMath", cmd);
} catch (NoMakefileFoundException | InvalidMakefileException | NoMakeCommandException ignored) {
fail();
}
}
@Test
public void withoutMake() {
Map<String, String> files = new HashMap<>();

View File

@ -127,6 +127,7 @@ func (w *AWSFunctionWorkload) executeCommand(ctx context.Context, command []stri
Cmd: command,
Files: w.fs,
}
log.WithField("request", data).Trace("Sending request to AWS")
rawData, err := json.Marshal(data)
if err != nil {
exit <- ExitInfo{uint8(1), fmt.Errorf("cannot stingify aws function request: %w", err)}