Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi map convert issue #1026

Closed
JoshuaXuDa opened this issue Mar 8, 2023 · 1 comment
Closed

multi map convert issue #1026

JoshuaXuDa opened this issue Mar 8, 2023 · 1 comment

Comments

@JoshuaXuDa
Copy link

@Test
public void test() {
    Jinjava jinjava = new Jinjava();
    Map<String, Object> context = new HashMap<>();
    Map<String, Object> pipelineRun = new HashMap<>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("product-name", "aaaa");
    pipelineRun.put("parameters", parameters);
    context.put("pipelineRun", pipelineRun);
    String template = "x-{{pipelineRun.parameters.product-name}}.zip";
    String renderedTemplate = jinjava.render(template, context);
    System.out.println(renderedTemplate);
}

expect result: x-aaaa.zip,but get x-0.zip, why

@didiercrunch
Copy link

@WindKn the issue here is that you use an hyphen (-) in a key name. The expression pipelineRun.parameters.product-name is translated to pipelineRun.parameters.product minus name. If you rename product-name to product_name it will work.

The below test passes.

@Test
public void test() {
    Jinjava jinjava = new Jinjava();
    Map<String, Object> context = new HashMap<>();
    Map<String, Object> pipelineRun = new HashMap<>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("product_name", "aaaa");
    pipelineRun.put("parameters", parameters);
    context.put("pipelineRun", pipelineRun);
    String template = "x-{{pipelineRun.parameters.product_name}}.zip";
    String renderedTemplate = jinjava.render(template, context);
    assertEquals(renderedTemplate, "x-aaaa.zip");
}

@jasmith-hs jasmith-hs closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants