Skip to content

Commit 5e847ba

Browse files
authored
Merge pull request #457 from mrfade/fix/i18n/escape-regex-dots
2 parents 3b6ad40 + 84ee656 commit 5e847ba

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

features/makejson.feature

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,3 +1118,72 @@ Feature: Split PO files into JSON files.
11181118
And the return code should be 0
11191119
And the foo-theme/foo-theme-de_DE-557240f2080a0894dbd39f5c2f559bf8.json file should exist
11201120
And the foo-theme/foo-theme-de_DE-a4e9f6529ffa4750907c140158b834b9.json file should exist
1121+
1122+
Scenario: Should correctly handle .min.js stripping and not corrupt admin files or edge cases
1123+
Given an empty foo-plugin directory
1124+
And a foo-plugin/foo-plugin-de_DE.po file:
1125+
"""
1126+
# Copyright (C) 2018 Foo Plugin
1127+
# This file is distributed under the same license as the Foo Plugin package.
1128+
msgid ""
1129+
msgstr ""
1130+
"Project-Id-Version: Foo Plugin\n"
1131+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
1132+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1133+
"Language-Team: LANGUAGE <[email protected]>\n"
1134+
"Language: de_DE\n"
1135+
"MIME-Version: 1.0\n"
1136+
"Content-Type: text/plain; charset=UTF-8\n"
1137+
"Content-Transfer-Encoding: 8bit\n"
1138+
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
1139+
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
1140+
"X-Domain: foo-plugin\n"
1141+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
1142+
1143+
#: script.min.js:5
1144+
msgid "Script"
1145+
msgstr "Script"
1146+
1147+
#: testadmin.js:15
1148+
msgid "Test Admin"
1149+
msgstr "Test Admin"
1150+
1151+
#: lib.min.min.js:30
1152+
msgid "Double Min Lib"
1153+
msgstr "Double Min Lib"
1154+
1155+
#: test.minified.js:40
1156+
msgid "Minified Test"
1157+
msgstr "Minified Test"
1158+
1159+
#: app.min.admin.js:45
1160+
msgid "Min Admin App"
1161+
msgstr "Min Admin App"
1162+
"""
1163+
1164+
When I run `wp i18n make-json foo-plugin`
1165+
Then STDOUT should contain:
1166+
"""
1167+
Success: Created 5 files.
1168+
"""
1169+
And the return code should be 0
1170+
And the foo-plugin/foo-plugin-de_DE-9a9569e9d73f33740eada95275da7f30.json file should contain:
1171+
"""
1172+
"source":"script.js"
1173+
"""
1174+
And the foo-plugin/foo-plugin-de_DE-539c08d0bcc09c88b8ea0aed7e1268a8.json file should contain:
1175+
"""
1176+
"source":"testadmin.js"
1177+
"""
1178+
And the foo-plugin/foo-plugin-de_DE-019463acf45a54a13438ace83bf8f270.json file should contain:
1179+
"""
1180+
"source":"lib.min.js"
1181+
"""
1182+
And the foo-plugin/foo-plugin-de_DE-879219342c5fd7dc4c85ccd6c9e5572f.json file should contain:
1183+
"""
1184+
"source":"test.minified.js"
1185+
"""
1186+
And the foo-plugin/foo-plugin-de_DE-5681c99983772839611729e61c726e79.json file should contain:
1187+
"""
1188+
"source":"app.min.admin.js"
1189+
"""

src/MakeJsonCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static function ( $reference ) use ( $extensions ) {
267267
$extension = pathinfo( $file, PATHINFO_EXTENSION );
268268

269269
return in_array( $extension, $extensions, true )
270-
? preg_replace( "/.min.{$extension}$/", ".{$extension}", $file )
270+
? preg_replace( "/\.min\.{$extension}$/", ".{$extension}", $file )
271271
: null;
272272
},
273273
$this->reference_map( $translation->getReferences(), $map )

0 commit comments

Comments
 (0)