-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add urldecode pebble function
close #2117
- Loading branch information
1 parent
db995d4
commit 5fc293e
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/java/io/kestra/core/runners/pebble/filters/UrlDecoderFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* This file is part of Pebble. | ||
* | ||
* Copyright (c) 2014 by Mitchell Bösecke | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
package io.kestra.core.runners.pebble.filters; | ||
|
||
import io.pebbletemplates.pebble.extension.Filter; | ||
import io.pebbletemplates.pebble.template.EvaluationContext; | ||
import io.pebbletemplates.pebble.template.PebbleTemplate; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class UrlDecoderFilter implements Filter { | ||
|
||
@Override | ||
public List<String> getArgumentNames() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, | ||
EvaluationContext context, int lineNumber) { | ||
if (input == null) { | ||
return null; | ||
} | ||
String arg = (String) input; | ||
try { | ||
arg = URLDecoder.decode(arg, "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
} | ||
return arg; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
core/src/test/java/io/kestra/core/runners/pebble/filters/UrlDecodeFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.kestra.core.runners.pebble.filters; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.runners.VariableRenderer; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest | ||
class UrlDecodeFilter { | ||
@Inject | ||
VariableRenderer variableRenderer; | ||
|
||
@Test | ||
void urldecode() throws IllegalVariableEvaluationException { | ||
String render = variableRenderer.render("{{ 'Kestra rulez !' | urlencode | urldecode }}", Map.of()); | ||
assertThat(render, is("Kestra rulez !")); | ||
} | ||
} |