Somewhat better handling of escaped '[...]' keys in yaml

This commit is contained in:
Kris De Volder
2020-09-30 13:59:29 -07:00
parent 034c04568a
commit fbdbc7cb83
3 changed files with 74 additions and 1 deletions

View File

@@ -76,7 +76,7 @@ public class YamlStructureParser {
* Pattern that matches a line starting with a 'simple key'
*/
public static final Pattern SIMPLE_KEY_LINE = Pattern.compile(
"^(\\w(\\.|\\w|-)*):( .*|$)");
"^((\\w(\\.|\\w|-)*)|(\\'(\\.|\\w|-|\\[|\\])*\\')):( .*|$)");
//TODO: the parrern above is too selective (e.g. in real yaml one can have
//spaces in simple keys and lots of other characters that this pattern does not
//allow. For now it is good enough because we are only interested in spring property

View File

@@ -33,6 +33,39 @@ import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser
public class YamlStructureParserTest {
@Test public void escapedStringKey() throws Exception {
MockYamlEditor editor;
editor = new MockYamlEditor(
"my:\n" +
" map:\n"+
" foobar:\n" +
" name: jeff"
);
assertParseOneDoc(editor,
"DOC(0): ",
" KEY(0): my:",
" KEY(2): map:",
" KEY(4): foobar:",
" KEY(6): name: jeff"
);
editor = new MockYamlEditor(
"my:\n" +
" map:\n"+
" '[foo.bar]':\n" +
" name: jeff"
);
assertParseOneDoc(editor,
"DOC(0): ",
" KEY(0): my:",
" KEY(2): map:",
" KEY(4): '[foo.bar]':",
" KEY(6): name: jeff"
);
}
@Test public void ignoreLeadingYamlCruftBeforeLeadingDocumentSeparator() throws Exception {
String[] stuffToIgnore = {
"#comment",