From 42daa25340564df3019e607fce9d1bbcdaec0f2a Mon Sep 17 00:00:00 2001 From: joostdekeijzer Date: Wed, 29 Jan 2014 12:59:49 +0100 Subject: [PATCH] Fix Console "extract i18n from sources" to handle quotes in Model::validate parameters correctly --- lib/Cake/Console/Command/Task/ExtractTask.php | 1 + .../Console/Command/Task/ExtractTaskTest.php | 3 ++ lib/Cake/Test/test_app/Model/Extract.php | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/Cake/Test/test_app/Model/Extract.php diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 2c547ed82..608e091ee 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -525,6 +525,7 @@ class ExtractTask extends AppShell { $msgid = $rule; } if ($msgid) { + $msgid = $this->_formatString(sprintf("'%s'", $msgid)); $details = array( 'file' => $file, 'line' => 'validation for field ' . $field diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index f157575be..e93a31eb4 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -351,6 +351,9 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '#msgid "Post body is super required"#'; $this->assertRegExp($pattern, $result); + + $this->assertContains('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly'); + $this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly'); } /** diff --git a/lib/Cake/Test/test_app/Model/Extract.php b/lib/Cake/Test/test_app/Model/Extract.php new file mode 100644 index 000000000..0cd7218c4 --- /dev/null +++ b/lib/Cake/Test/test_app/Model/Extract.php @@ -0,0 +1,45 @@ + array( + 'custom' => array( + 'rule' => array('custom', '.*'), + 'allowEmpty' => true, + 'required' => false, + 'message' => 'double "quoted" validation' + ), + 'between' => array( + 'rule' => array('between', 5, 15), + 'message' => "single 'quoted' validation" + ) + ), + ); + +}