Skip to content

Commit

Permalink
Fix MVELTemplateEngineImpl file resolution on Windows (#2516)
Browse files Browse the repository at this point in the history
See #2514

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
  • Loading branch information
tsegismont authored Nov 22, 2023
1 parent 026648c commit b0860a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.common.template.CachingTemplateEngine;
import io.vertx.ext.web.common.template.impl.TemplateHolder;
import io.vertx.ext.web.templ.mvel.MVELTemplateEngine;
import org.mvel2.integration.impl.ImmutableDefaultFactory;
import org.mvel2.templates.CompiledTemplate;
import org.mvel2.templates.TemplateCompiler;
import org.mvel2.templates.TemplateRuntime;
import org.mvel2.util.StringAppender;

import io.vertx.ext.web.templ.mvel.MVELTemplateEngine;

import java.nio.charset.Charset;
import java.util.Map;

import static io.vertx.core.impl.Utils.isWindows;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
Expand All @@ -51,7 +52,7 @@ public Future<Buffer> render(Map<String, Object> context, String templateFile) {
TemplateHolder<CompiledTemplate> template = getTemplate(src);

if (template == null) {
int idx = src.lastIndexOf('/');
int idx = findLastFileSeparator(src);
String baseDir = "";
if (idx != -1) {
baseDir = src.substring(0, idx);
Expand Down Expand Up @@ -85,4 +86,10 @@ public Future<Buffer> render(Map<String, Object> context, String templateFile) {
}
}

private static int findLastFileSeparator(String src) {
if (isWindows()) {
return Math.max(src.lastIndexOf('/'), src.lastIndexOf('\\'));
}
return src.lastIndexOf('/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.file.FileSystemOptions;
import io.vertx.core.impl.Utils;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.ext.web.common.template.TemplateEngine;
import io.vertx.ext.web.templ.mvel.MVELTemplateEngine;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -81,10 +79,6 @@ public void MVELTemplateTestMVELTemplateTestMVELTemplateTest(TestContext should)

@Test
public void testTemplateHandlerWithInclude(TestContext should) {
// Cannot pass on windows due to
// File file = new File(runtime.getRelPath().peek() + "/" + fileName);
// in org.mvel2.templates.res.CompiledIncludeNode
Assume.assumeFalse(Utils.isWindows());
TemplateEngine engine = MVELTemplateEngine.create(vertx);

final JsonObject context = new JsonObject()
Expand Down

0 comments on commit b0860a7

Please sign in to comment.