From 5ca7345671490cbc9dfd3e122a4dfc617e977992 Mon Sep 17 00:00:00 2001 From: Guillaume Galy Date: Wed, 11 Jan 2023 11:14:42 +0100 Subject: [PATCH] fix: inconsistent YAML multiline parsing (#475) When the YAML block scalar (multiline string) syntax is used with only one line of text, the single line is not matched by the current regexp. It currently only works with at least two lines. This fixes the regexp by adding a special case for a single line after the first indentation in the block. --- lexers/embedded/yaml.xml | 2 +- lexers/testdata/yaml.actual | 8 ++++++-- lexers/testdata/yaml.expected | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lexers/embedded/yaml.xml b/lexers/embedded/yaml.xml index baa7bd5de..97a0b6ed9 100644 --- a/lexers/embedded/yaml.xml +++ b/lexers/embedded/yaml.xml @@ -49,7 +49,7 @@ - + diff --git a/lexers/testdata/yaml.actual b/lexers/testdata/yaml.actual index 772e43fbe..ddb417e5c 100644 --- a/lexers/testdata/yaml.actual +++ b/lexers/testdata/yaml.actual @@ -105,7 +105,9 @@ e: |+ f: >+ multiline folded keep one space line 2 -g: test +g: | + multiline literal with only one line +h: test block_scalars_with_indent: a: | @@ -129,7 +131,9 @@ block_scalars_with_indent: f: >+ multiline folded keep line 2 - g: test + g: | + multiline literal with only one line + h: test #################### # COLLECTION TYPES # diff --git a/lexers/testdata/yaml.expected b/lexers/testdata/yaml.expected index f054e3c07..a73b48a0a 100644 --- a/lexers/testdata/yaml.expected +++ b/lexers/testdata/yaml.expected @@ -251,6 +251,12 @@ {"type":"NameTag","value":"g"}, {"type":"Punctuation","value":":"}, {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"LiteralStringDoc","value":"\n multiline literal with only one line"}, + {"type":"TextWhitespace","value":" \n"}, + {"type":"NameTag","value":"h"}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, {"type":"Literal","value":"test"}, {"type":"TextWhitespace","value":"\n\n"}, {"type":"NameTag","value":"block_scalars_with_indent"}, @@ -297,6 +303,12 @@ {"type":"NameTag","value":"g"}, {"type":"Punctuation","value":":"}, {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"LiteralStringDoc","value":"\n multiline literal with only one line"}, + {"type":"TextWhitespace","value":" \n "}, + {"type":"NameTag","value":"h"}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, {"type":"Literal","value":"test"}, {"type":"TextWhitespace","value":"\n\n"}, {"type":"Comment","value":"####################"},