Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 2c74548

Browse files
committed
Correctly parse code string even when only the shebang is here. Fix #52
1 parent ec728c6 commit 2c74548

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/java/org/scijava/jupyter/kernel/evaluator/ScijavaEvaluator.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private void addLanguage(String languageName) {
132132
String firstLanguage = this.scriptEngines.keySet().iterator().next();
133133
bindings = this.scriptEngines.get(firstLanguage).getBindings(ScriptContext.ENGINE_SCOPE);
134134
}
135-
135+
136136
log.info("Script Language for '" + languageName + "' found.");
137137
ScriptLanguage scriptLanguage = scriptService.getLanguageByName(languageName);
138138
this.scriptLanguages.put(languageName, scriptLanguage);
@@ -154,10 +154,20 @@ private void addLanguage(String languageName) {
154154
private String setLanguage(String code) {
155155

156156
if (code.startsWith("#!")) {
157-
this.languageName = code.substring(2, code.indexOf("\n")).trim();
158157

159-
// Return the code string without the first line
160-
code = code.substring(code.indexOf(System.getProperty("line.separator")) + 1);
158+
// If code is composed of multiple lines
159+
if (code.split("\n").length > 1) {
160+
this.languageName = code.substring(2, code.indexOf("\n")).trim();
161+
162+
// Return the code string without the first line
163+
code = code.substring(code.indexOf(System.getProperty("line.separator")) + 1);
164+
} // If only one line
165+
else {
166+
this.languageName = code.substring(2).trim();
167+
168+
code = "";
169+
}
170+
161171
}
162172

163173
this.addLanguage(this.languageName);

0 commit comments

Comments
 (0)