From 7cbbc8bf20ef8ce0e3c54aa771ffc76823c64a6f Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 28 Mar 2021 09:43:26 -0400 Subject: [PATCH 1/5] do not quote class names as keys --- src/Parse/Processor/Symfony3Processor.php | 2 +- tests/Parse/YamlTest.php | 3 +++ tests/fixtures/yaml/symfony3.yaml | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Parse/Processor/Symfony3Processor.php b/src/Parse/Processor/Symfony3Processor.php index 8eed335a9..d4ae22bbb 100644 --- a/src/Parse/Processor/Symfony3Processor.php +++ b/src/Parse/Processor/Symfony3Processor.php @@ -21,7 +21,7 @@ public function preprocess($text) foreach ($lines as &$line) { // Surround array keys with quotes if not already - $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:]+[\'"]{0})\s*:/m', function ($matches) { + $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:\\\]+[\'"]{0})\s*:/m', function ($matches) { return $matches[1] . '"' . trim($matches[2]) . '":'; }, rtrim($line)); } diff --git a/tests/Parse/YamlTest.php b/tests/Parse/YamlTest.php index 098af0b43..5288f6f2d 100644 --- a/tests/Parse/YamlTest.php +++ b/tests/Parse/YamlTest.php @@ -144,6 +144,9 @@ public function testSymfony3YamlFileWithProcessor() 'false' => false, ], ], + 'testClass' => [ + 'My\Class\Path' => 'value' + ], ], ], ], $yaml); diff --git a/tests/fixtures/yaml/symfony3.yaml b/tests/fixtures/yaml/symfony3.yaml index a51719f6d..22b7f530e 100644 --- a/tests/fixtures/yaml/symfony3.yaml +++ b/tests/fixtures/yaml/symfony3.yaml @@ -29,3 +29,5 @@ form: options: true: true false: false + testClass: + My\Class\Path: value From d3feceb17f521f806bd5bdb134da88d6c8ff9913 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 28 Mar 2021 11:45:14 -0400 Subject: [PATCH 2/5] use single quotes instead of double quotes --- src/Parse/Processor/Symfony3Processor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Parse/Processor/Symfony3Processor.php b/src/Parse/Processor/Symfony3Processor.php index d4ae22bbb..ced3f14a4 100644 --- a/src/Parse/Processor/Symfony3Processor.php +++ b/src/Parse/Processor/Symfony3Processor.php @@ -21,8 +21,8 @@ public function preprocess($text) foreach ($lines as &$line) { // Surround array keys with quotes if not already - $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:\\\]+[\'"]{0})\s*:/m', function ($matches) { - return $matches[1] . '"' . trim($matches[2]) . '":'; + $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:]+[\'"]{0})\s*:/m', function ($matches) { + return $matches[1] . "'" . trim($matches[2]) . "':"; }, rtrim($line)); } From b6c02a1cf3aa3cf0c7f8170db51e453b402d1dc1 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 28 Mar 2021 16:12:57 -0400 Subject: [PATCH 3/5] add double quoting tests --- tests/Parse/YamlTest.php | 4 ++++ tests/fixtures/yaml/symfony3.yaml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/Parse/YamlTest.php b/tests/Parse/YamlTest.php index 5288f6f2d..4022a20ec 100644 --- a/tests/Parse/YamlTest.php +++ b/tests/Parse/YamlTest.php @@ -147,6 +147,10 @@ public function testSymfony3YamlFileWithProcessor() 'testClass' => [ 'My\Class\Path' => 'value' ], + 'testBothQuoting' => [ + 'complex1' => 'this is "very" complex quoting', + 'complex2' => 'this is also \'very\' complex quoting', + ], ], ], ], $yaml); diff --git a/tests/fixtures/yaml/symfony3.yaml b/tests/fixtures/yaml/symfony3.yaml index 22b7f530e..65887f923 100644 --- a/tests/fixtures/yaml/symfony3.yaml +++ b/tests/fixtures/yaml/symfony3.yaml @@ -31,3 +31,7 @@ form: false: false testClass: My\Class\Path: value + testBothQuoting: + complex1: 'this is "very" complex quoting' + complex2: "this is also 'very' complex quoting" + From 93c19011ee44da331dd41a23b969d7e2e6154011 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 28 Mar 2021 16:34:21 -0400 Subject: [PATCH 4/5] skip commented-out entries, they are handled properly by the Yaml parser --- src/Parse/Processor/Symfony3Processor.php | 2 +- tests/Parse/YamlTest.php | 3 +++ tests/fixtures/yaml/symfony3.yaml | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Parse/Processor/Symfony3Processor.php b/src/Parse/Processor/Symfony3Processor.php index ced3f14a4..bc9085db7 100644 --- a/src/Parse/Processor/Symfony3Processor.php +++ b/src/Parse/Processor/Symfony3Processor.php @@ -21,7 +21,7 @@ public function preprocess($text) foreach ($lines as &$line) { // Surround array keys with quotes if not already - $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:]+[\'"]{0})\s*:/m', function ($matches) { + $line = preg_replace_callback('/^( *)([\'"]{0}[^\'"\n\r:#]+[\'"]{0})\s*:/m', function ($matches) { return $matches[1] . "'" . trim($matches[2]) . "':"; }, rtrim($line)); } diff --git a/tests/Parse/YamlTest.php b/tests/Parse/YamlTest.php index 4022a20ec..0cf7e70ec 100644 --- a/tests/Parse/YamlTest.php +++ b/tests/Parse/YamlTest.php @@ -151,6 +151,9 @@ public function testSymfony3YamlFileWithProcessor() 'complex1' => 'this is "very" complex quoting', 'complex2' => 'this is also \'very\' complex quoting', ], + 'testComment' => [ + 'key' => 'value', + ], ], ], ], $yaml); diff --git a/tests/fixtures/yaml/symfony3.yaml b/tests/fixtures/yaml/symfony3.yaml index 65887f923..96180ec72 100644 --- a/tests/fixtures/yaml/symfony3.yaml +++ b/tests/fixtures/yaml/symfony3.yaml @@ -34,4 +34,7 @@ form: testBothQuoting: complex1: 'this is "very" complex quoting' complex2: "this is also 'very' complex quoting" + testComment: + key: value + #comment: comments should be removed From 22cb2db4a07f6abbccd6ea1211de7d63d2e677cd Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 28 Mar 2021 16:41:17 -0400 Subject: [PATCH 5/5] add test for quoted in the middle of a value --- tests/Parse/YamlTest.php | 3 ++- tests/fixtures/yaml/symfony3.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Parse/YamlTest.php b/tests/Parse/YamlTest.php index 0cf7e70ec..0e5d63bfc 100644 --- a/tests/Parse/YamlTest.php +++ b/tests/Parse/YamlTest.php @@ -147,9 +147,10 @@ public function testSymfony3YamlFileWithProcessor() 'testClass' => [ 'My\Class\Path' => 'value' ], - 'testBothQuoting' => [ + 'testQuoting' => [ 'complex1' => 'this is "very" complex quoting', 'complex2' => 'this is also \'very\' complex quoting', + 'middle' => 'this string is "quoted" in the middle', ], 'testComment' => [ 'key' => 'value', diff --git a/tests/fixtures/yaml/symfony3.yaml b/tests/fixtures/yaml/symfony3.yaml index 96180ec72..98cd26cde 100644 --- a/tests/fixtures/yaml/symfony3.yaml +++ b/tests/fixtures/yaml/symfony3.yaml @@ -31,9 +31,10 @@ form: false: false testClass: My\Class\Path: value - testBothQuoting: + testQuoting: complex1: 'this is "very" complex quoting' complex2: "this is also 'very' complex quoting" + middle: this string is "quoted" in the middle testComment: key: value #comment: comments should be removed