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

File scanner: Ignore escaped quotes when detecting end of string (\') #299

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function findTranslations()
'('. // Start a new group to match:
'.+'. // Must start with group
')'. // Close group
"[\'\"]". // Closing quote
"(?<!\\\\)[\'\"]". // Closing quote (don't match if escaped with backslash)
"\s*". // Whitespace after param
"[\),]"; // Close parentheses or new parameter

Expand Down
2 changes: 1 addition & 1 deletion tests/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '', '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);
}
}
6 changes: 5 additions & 1 deletion tests/fixtures/scan-tests/__.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ __('This will go in the JSON array')

__(
'This will also go in the JSON array'
)
)

__('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!')