Skip to content

Commit

Permalink
Disallow using dots in mustache data property names
Browse files Browse the repository at this point in the history
This was previously seen as a feature being added, but this is
not allowed according to the mustache spec
  • Loading branch information
JamyGolden committed Sep 1, 2024
1 parent 95b4e92 commit d4c03ee
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions ribboncurls-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.4.0] - 2024-09-02

### Removed

- Update to latest `ribboncurls` library, where a previously existing
"feature" has been removed because the feature, allowing for mustache
data properties to include dots in the name, is disallowed in the
mustache spec.

## [0.3.2] - 2024-08-17

### Changed
Expand Down Expand Up @@ -37,6 +46,7 @@

- Initial release

[0.4.0]: https://github.com/tinted-theming/ribboncurls/compare/v0.3.2...v0.4.0
[0.3.2]: https://github.com/tinted-theming/ribboncurls/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/tinted-theming/ribboncurls/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/tinted-theming/ribboncurls/compare/v0.2.1...v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions ribboncurls-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ribboncurls-cli"
version = "0.3.2"
version = "0.4.0"
edition = "2021"
authors = ["Tinted Theming <[email protected]>"]
license = "MPL-2.0"
Expand All @@ -19,7 +19,7 @@ serde_yaml = "0.9.33"

[dependencies.ribboncurls]
path = "../ribboncurls"
version = "0.3.1"
version = "0.4.0"

[[bin]]
name = "ribboncurls"
Expand Down
8 changes: 8 additions & 0 deletions ribboncurls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.4.0 - 2024-09-02

## Changed

- The "feature" where properties with dots in data property name is
supported is a bug according to the mustache spec so it's been
removed.

## 0.3.1 - 2024-08-17

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion ribboncurls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ribboncurls"
version = "0.3.1"
version = "0.4.0"
edition = "2021"
build = "build.rs"
authors = ["Tinted Theming <[email protected]>"]
Expand Down
26 changes: 4 additions & 22 deletions ribboncurls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,13 @@ fn get_value_from_context<'a>(ctx: &'a RenderCtx, path: &str) -> Option<&'a Valu
};
}

// if `path`'s `a` in `a.b.c.d` doesn't exist in latest context, search up the context stack.
// If it doesn't exist anywhere, assume `"a.b"` is the property name and repeat. Once `a.b`
// property is found, assume `c` in `c.d` is a Mapping, if nothing is found assume `"c.d"` is a
// property name and search
// If `path`'s `a` in `a.b.c.d` doesn't exist in latest context, search up the context stack.
if !ctx.data_stack.is_empty() {
let path_vec = path.split('.');
let mut possible_path_list = Vec::default();
let mut path_item_prefix = String::default();

for path_item in path_vec {
let new_path_item = if path_item_prefix.is_empty() {
path_item.to_string()
} else {
format!("{}.{}", path_item_prefix, path_item)
};
possible_path_list.push(new_path_item.clone());
path_item_prefix = new_path_item;
}

for possible_path in &possible_path_list {
for possible_path in path_vec {
for context in ctx.data_stack.iter().rev() {
let value_option = context.get(possible_path);

if let Some(value) = value_option {
if let Some(value) = get_value(context, possible_path) {
if let Some(target_property_name) =
&path.strip_prefix(&format!("{}.", possible_path))
{
Expand Down Expand Up @@ -416,10 +399,9 @@ fn render_sequence_of_sequences(
if let Some(Value::Sequence(sequence)) = ctx.data_stack.last() {
let sequence_clone = sequence.clone();
for item in sequence_clone {
let meh = item.clone();
let name = serde_yaml_value_to_string(&item);
ctx.section_path.push(name);
ctx.data_stack.push(meh);
ctx.data_stack.push(item.clone());
if is_value_truthy(&item) {
let section_output = render_syntax_tree(items, ctx)?;

Expand Down
6 changes: 3 additions & 3 deletions ribboncurls/tests/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn data_with_nested_sections() {
}

#[test]
fn prefix_variable_with_dots_is_string() {
fn data_property_with_dots_is_not_recognised() {
let template = "{{#a}}{{#b}}{{c.d.e.f}}{{/b}}{{/a}}";
let data = r#"
a:
Expand All @@ -213,7 +213,7 @@ fn prefix_variable_with_dots_is_string() {
"#;
let template = ribboncurls::render(template, data, None).unwrap();

assert_eq!(template, "Tinted Theming!");
assert!(template.is_empty());
}

#[test]
Expand All @@ -227,7 +227,7 @@ fn prefix_variable_with_dots_is_string_and_suffix_with_dots_is_string() {
"#;
let template = ribboncurls::render(template, data, None).unwrap();

assert_eq!(template, "Tinted Theming!");
assert!(template.is_empty());
}

#[test]
Expand Down

0 comments on commit d4c03ee

Please sign in to comment.