Skip to content

Commit

Permalink
Workaround for returning values containing unicode line-ends.
Browse files Browse the repository at this point in the history
Should be fixed in Cordova.

Discussion here: apache/cordova-discuss#57
  • Loading branch information
Toon Toetenel committed May 28, 2018
1 parent f2591fc commit 02d2dc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/android/NativeStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ public void run() {
String s = sharedPref.getString(ref, "nativestorage_null");
if (s.equals("nativestorage_null")) {
callbackContext.error(2); // item not found
} else callbackContext.success(s);
} else {
// Workaround returning values containing unicode line-ends
s = s.replaceAll("\u2028", "");
s = s.replaceAll("\u2029", "");
callbackContext.success(s);
}
} catch (Exception e) {
Log.e(TAG, "getItem failed :", e);
callbackContext.error(e.getMessage());
Expand Down
5 changes: 5 additions & 0 deletions src/ios/NativeStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ - (void) getItem: (CDVInvokedUrlCommand*) command
if(reference!=nil)
{
NSString* aString = [[NSUserDefaults standardUserDefaults] stringForKey:reference];

// Workaround returning values containing unicode line-ends
aString = [aString stringByReplacingOccurrencesOfString:@"\u2028" withString:@""];
aString = [aString stringByReplacingOccurrencesOfString:@"\u2029" withString:@""];

pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:aString];
if(aString==nil)
{
Expand Down

0 comments on commit 02d2dc1

Please sign in to comment.