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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS) Does not support encoded characters in project name (&) #77

Open
florian72810 opened this issue Oct 7, 2022 · 2 comments
Open

Comments

@florian72810
Copy link

florian72810 commented Oct 7, 2022

Hello 馃憢
Thanks for this plugin.

I have a use-case where the project name contains encoded characters food&good.

In my config.xml, the & is encoded as &amp; -> <name>food&amp;good</name>

Cordova handles this name and decode &amp;. Everything works fine on Xcode, I can build the project.

When this plugin is added, the prepare process return an error:

Executing script found in plugin cordova-plugin-localization-strings for hook "after_prepare": plugins/cordova-plugin-localization-strings/scripts/create_strings.js
Error: Cannot read property 'project' of undefined

I search the root cause and it seems the plugin is trying to find the project at path /food&amp;good/ and does not find it. It is expected as the project path is food&good. The function getProjectName does not decoded encoded characters.

To reproduce

  1. start a new Cordova project cordova create hello com.example.hello "Hello&World"
  2. go to project cd hello
  3. add iOS platform cordova platform add ios
  4. prepare iOS (it does work) cordova prepare ios
  5. add plugin cordova plugin add cordova-plugin-localization-strings
  6. prepare iOS again (it does NOT work) cordova prepare ios

Quick and dirty fix

For my case, I change the file scripts/create_ios_strings.js

diff --git a/node_modules/cordova-plugin-localization-strings/scripts/create_ios_strings.js b/node_modules/cordova-plugin-localization-strings/scripts/create_ios_strings.js
index 5d46c73..f286a2f 100755
--- a/node_modules/cordova-plugin-localization-strings/scripts/create_ios_strings.js
+++ b/node_modules/cordova-plugin-localization-strings/scripts/create_ios_strings.js
@@ -24,7 +24,7 @@ function getProjectName() {
     if (!matches)
         matches = config.match(new RegExp('<name short=".*?">(.*?)</name>', 'i'));
 
-    return (matches && matches[1]) || null;
+    return (matches && matches[1]).replace('&amp;','&') || null;
 }
 
 function initIosDir() {

Not dirty fix

I tried to find how cordova decode the project name, but I did not find it. It seems he lib can do this, but it adds a dependency (https://www.npmjs.com/package/he#hedecodehtml-options)

@rodrigograca31
Copy link
Collaborator

Doesnt affect Android? 馃

@florian72810
Copy link
Author

I don't use it with Android, I can't confirm if the plugin works fully as expected.

With the same reproduction steps, Android does work, no error at prepare step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants