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

enhancement(remap): Support identifiers with leading numeric characters as fields in path #7045

Merged
merged 7 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference/remap/expressions/path.cue
Expand Up @@ -87,8 +87,8 @@ remap: expressions: path: {
title: "Valid path characters"
description: """
Path segments only allow for underscores and ASCII alpha-numeric characters
(`[a-zA-Z0-9_]`). Segments must be delimited with periods (`.`). If a segment contains
characters outside of this list it must be quoted.
(`[a-zA-Z0-9_]`) where integers like `0` are not supported. Quoting
can be used to escape these constraints.
"""
}
}
Expand Down
26 changes: 26 additions & 0 deletions lib/vrl/parser/src/lex.rs
Expand Up @@ -908,7 +908,13 @@ impl<'input> Lexer<'input> {
fn numeric_literal(&mut self, start: usize) -> SpannedResult<'input, usize> {
ktff marked this conversation as resolved.
Show resolved Hide resolved
let (end, int) = self.take_while(start, |ch| is_digit(ch) || ch == '_');

let negative = self.input.get(start..start + 1) == Some("-");
match self.peek() {
Some((_, ch)) if is_ident_continue(ch) && !negative => {
self.bump();
let (end, ident) = self.take_while(start, is_ident_continue);
Ok((start, Token::ident(ident), end))
}
Some((_, '.')) => {
self.bump();
let (end, float) = self.take_while(start, |ch| is_digit(ch) || ch == '_');
Expand Down Expand Up @@ -1724,6 +1730,26 @@ mod test {
);
}

#[test]
fn queries_digit_path() {
test(
data(r#".0foo foo.00_7bar.tar"#),
vec![
(r#"~ "#, LQuery),
(r#"~ "#, Dot),
(r#" ~~~~ "#, Identifier("0foo")),
(r#" ~ "#, RQuery),
(r#" ~ "#, LQuery),
(r#" ~~~ "#, Identifier("foo")),
(r#" ~ "#, Dot),
(r#" ~~~~~~~ "#, Identifier("00_7bar")),
(r#" ~ "#, Dot),
(r#" ~~~"#, Identifier("tar")),
(r#" ~"#, RQuery),
],
);
}

#[test]
fn queries_nested_delims() {
use StringLiteral as S;
Expand Down
4 changes: 4 additions & 0 deletions lib/vrl/tests/tests/expressions/query/coalesce.vrl
@@ -0,0 +1,4 @@
# result: 2

foo = { "0bar": 2 }
foo.(a | 0bar)
4 changes: 2 additions & 2 deletions lib/vrl/tests/tests/expressions/query/mixed.vrl
Expand Up @@ -5,8 +5,8 @@
{
"foo": [
{
"bar": parse_json!("{ \"baz\": true }").baz,
"bar": parse_json!("{ \"baz\": {\"0tar\": true} }").baz,
}
]
}
][1].foo[0].bar
][1].foo[0].bar.0tar