From f3fef17d4b725335992670e313cb27295f91bba3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 23 May 2020 18:18:59 -0400 Subject: [PATCH] I was wrong, html escape filter is appended even if an html escape filter is already there. --- js/test_cases/filters/README.md | 2 +- js/test_cases/filters/main.dust | 1 + src/renderer/renderer.rs | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/js/test_cases/filters/README.md b/js/test_cases/filters/README.md index 3325603..028a871 100644 --- a/js/test_cases/filters/README.md +++ b/js/test_cases/filters/README.md @@ -4,5 +4,5 @@ HTML Escaping Dust automatically applies the `|h` filter to html escape unless `|s` is applied to disable automatic html escaping. It seems that if you manually specify `|h` and `|s` in the same filter, then it still html escapes, so my theory on the logic is: Iterate over all filters -If `|s` or `|h` is not present append `|h`, otherwise, leave filters as-in +If `|s` is not present append `|h`, otherwise, leave filters as-in During render, `|s` does nothing, so we can just remove it on the dust side to prevent confusion. diff --git a/js/test_cases/filters/main.dust b/js/test_cases/filters/main.dust index 3fe4c40..df5b2d4 100644 --- a/js/test_cases/filters/main.dust +++ b/js/test_cases/filters/main.dust @@ -2,6 +2,7 @@ Special characters: {special_characters}{~n} Special characters html escaping disabled: {special_characters|s}{~n} Special characters html escaping disabled and enabled: {special_characters|s|h}{~n} Special characters html escaping enabled and disabled: {special_characters|h|s}{~n} +Special characters html escaped once: {special_characters|h}{~n} Special characters html escaped twice: {special_characters|h|h}{~n} diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 0c25eae..eab630e 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -510,10 +510,7 @@ impl<'a> DustRenderer<'a> { // If the user has not specified any escaping filter (|s or // |h), automatically add an html escape filter - if !filters - .iter() - .any(|f| f == &Filter::DisableHtmlEncode || f == &Filter::HtmlEncode) - { + if !filters.iter().any(|f| f == &Filter::DisableHtmlEncode) { final_filters.push(Filter::HtmlEncode); } final_filters