Skip to content

Commit

Permalink
Fixes parsing of engine names in auto-script contexts for languages o…
Browse files Browse the repository at this point in the history
…ther than default js.
  • Loading branch information
ckramp committed May 15, 2024
1 parent c5c7919 commit d1fcd10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public ProxyExecutable getProxyExecutable(final ActionContext actionContext, fin
final Snippet snippet = getSnippet();

if (snippet != null && !snippet.getSource().isEmpty()) {
final String[] splitSnippet = Scripting.splitSnippetIntoEngineAndScript(snippet.getSource());
final String engineName = splitSnippet[0];
final String engineName = snippet.getEngineName();

if (!engineName.isEmpty()) {
final SecurityContext securityContext = actionContext.getSecurityContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,24 @@ public boolean isStatic() {
@Override
public Snippet getSnippet() {

Snippet snippet = null;

if (source != null) {

final String[] splitSource = Scripting.splitSnippetIntoEngineAndScript(source);

if ("js".equals(splitSource[0])) {

return new Snippet(name, source);
snippet = new Snippet(name, splitSource[1]);
} else {

return new Snippet(name, source, false);
snippet = new Snippet(name, splitSource[1], false);
}
}
return null;

snippet.setEngineName(splitSource[0]);
}

return snippet;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static String[] splitSnippetIntoEngineAndScript(final String snippet) {
script = snippet.substring(isAutoScriptingEnv ? 1 : 3, snippet.length() - (isAutoScriptingEnv ? 1 : 2));
} else {

final Matcher matcher = ScriptEngineExpression.matcher(isAutoScriptingEnv ? String.format("${%s!}", snippet) : snippet);
final Matcher matcher = ScriptEngineExpression.matcher(isAutoScriptingEnv ? String.format("${%s}", snippet) : snippet);
if (matcher.matches()) {

engine = matcher.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Snippet {
private String source = null;
private String transcribedSource = null;
private String mimeType = "application/javascript";
private String engineName = null;
private boolean embed = true;
private int startRow = 0;

Expand Down Expand Up @@ -89,4 +90,12 @@ public String getTranscribedSource() {
public void setTranscribedSource(final String transcribedSource) {
this.transcribedSource = transcribedSource;
}

public String getEngineName() {
return this.engineName;
}

public void setEngineName(final String engineName) {
this.engineName = engineName;
}
}

0 comments on commit d1fcd10

Please sign in to comment.