Skip to content

Commit f4871d5

Browse files
add modifier filter to debug
1 parent f100f97 commit f4871d5

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

doc/bif-debug.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Stray debug bifs show an error message with a reminder to be removed in producti
2222
Modifiers:
2323
----------
2424

25-
```html
25+
```text
2626
{:^debug; ... :}
2727
{:!debug; ... :}
28+
{:&debug; ... :}
2829
```
2930
### Modifier: ^ (upline)
3031

@@ -55,6 +56,21 @@ Although any key is ignored, it might be confusing to do this:
5556
{:!debug; data->key :}
5657
```
5758

59+
### Modifier: & (filter):
60+
61+
Escapes special HTML characters and braces:
62+
63+
```text
64+
& → &
65+
< → &lt;
66+
> → &gt;
67+
" → &quot;
68+
' → &#x27;
69+
/ → &#x2F;
70+
{ → &#123;
71+
} → &#125;
72+
```
73+
5874
No flags
5975
--------
6076

@@ -211,4 +227,9 @@ If cache is active, the output will also be saved to the cache. If you wish to a
211227
:}
212228
```
213229

230+
Prevent HTML tags from being parsed:
231+
232+
```text
233+
{:&debug; data :}
234+
```
214235
---

src/bif/parse_bif_debug.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#![doc = include_str!("../../doc/bif-debug.md")]
22

3-
use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
3+
use crate::{
4+
bif::constants::*,
5+
bif::Bif,
6+
bif::BifError,
7+
constants::*,
8+
utils::*,
9+
};
410
use std::fs;
511
use std::path::Path;
612
use std::time::{SystemTime, Duration};
@@ -10,7 +16,7 @@ impl<'a> Bif<'a> {
1016
{:debug; data->key :}
1117
*/
1218
pub(crate) fn parse_bif_debug(&mut self) -> Result<(), BifError> {
13-
if self.mod_filter || self.mod_scope {
19+
if self.mod_scope {
1420
return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
1521
}
1622

@@ -61,6 +67,12 @@ impl<'a> Bif<'a> {
6167
None => format!("Undefined: '{}'", self.code),
6268
};
6369

70+
if self.mod_filter {
71+
// unescape_chars for prevent double encoding
72+
let tmp = unescape_chars(&self.out, true);
73+
self.out = escape_chars(&tmp, true);
74+
}
75+
6476
Ok(())
6577
}
6678

0 commit comments

Comments
 (0)