From 09ddfefc1030795201a2623e24a7388dbd7c3c1b Mon Sep 17 00:00:00 2001 From: q-- <2470175+q--@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:14:38 +0100 Subject: [PATCH 1/2] ScannerTest: Fix misordered assertEquals arguments --- tests/ScannerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ScannerTest.php b/tests/ScannerTest.php index bceee00e..3f43060d 100644 --- a/tests/ScannerTest.php +++ b/tests/ScannerTest.php @@ -31,7 +31,7 @@ public function it_finds_all_translations() $this->scanner = app()->make(Scanner::class); $matches = $this->scanner->findTranslations(); - $this->assertEquals($matches, ['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]]); + $this->assertEquals(['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]], $matches); $this->assertCount(2, $matches); } } From c2bccc3e2bb10a2253f545b6287310d14c69a15a Mon Sep 17 00:00:00 2001 From: q-- <2470175+q--@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:49:51 +0100 Subject: [PATCH 2/2] Ignore escaped quotes when detecting end of string So, for `__('\'Hello\', World!')` it previously detected the string `'Hello\`; after this fix, it'll properly detect `'Hello', World!` --- src/Scanner.php | 2 +- tests/ScannerTest.php | 2 +- tests/fixtures/scan-tests/__.txt | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Scanner.php b/src/Scanner.php index 31c794ff..a191e021 100644 --- a/src/Scanner.php +++ b/src/Scanner.php @@ -41,7 +41,7 @@ public function findTranslations() '('. // Start a new group to match: '.+'. // Must start with group ')'. // Close group - "[\'\"]". // Closing quote + "(?scanner = app()->make(Scanner::class); $matches = $this->scanner->findTranslations(); - $this->assertEquals(['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]], $matches); + $this->assertEquals(['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'The first half of this sentence should go into the \'JSON array\', but the second part should as well!' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]], $matches); $this->assertCount(2, $matches); } } diff --git a/tests/fixtures/scan-tests/__.txt b/tests/fixtures/scan-tests/__.txt index 8b04d350..0a0cc475 100644 --- a/tests/fixtures/scan-tests/__.txt +++ b/tests/fixtures/scan-tests/__.txt @@ -3,4 +3,8 @@ __('This will go in the JSON array') __( 'This will also go in the JSON array' -) \ No newline at end of file +) + +__('This will go in the JSON array, and it\'ll properly unescape the apostrophe.') + +__('The first half of this sentence should go into the \'JSON array\', but the second part should as well!')