cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

Fence notifications with text attributes that contain single quotes #279

Open cosnofski opened 6 years ago

cosnofski commented 6 years ago

A fence with a single quote in the notification.text attribute causes geofencePlugin.getTransitions not to fire. Tried with a single quote and an escaped single quote. (note: only tested in iOS)

Question: Is there a good reason to keep the single quotes in the eval'd expression (like old browser compatibility) or can they safely be removed in GeofencePlugin.swift?

fence:

let fence = { "id" : fence-0001', "radius" : 200, "longitude" : -95.712891, "transitionType" : 3, "latitude" : 37.09024, "notification" : { "id" : 817263, "title" : "You Crossed a Fence", "openAppOnClick" : true, "text" : "You're near a fence" } }

The plugin passes a javascript string to the getTransitions() function that is wrapped in single quotes which is evaluated by the webView (in my case I'm using cordova-plugin-ionic-webview@1.1.19)

Throws the error:

GeofencePlugin - Optional(Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=SyntaxError: Unexpected identifier 're'. Expected ')' to end an argument list., WKJavaScriptExceptionColumnNumber=0, ...})

Here is the js string to be eval'd by WKWebView...

setTimeout('geofence.onTransitionReceived([{"latitude":37.09024,"notification":{"id":817263,"title":"You Crossed a Fence","openAppOnClick":true,"text":"You're near a fence"},"radius":200,"transitionType":1,"id":"fence-0001","longitude":-95.712891}])',0)

Removing the single quote from the json or the keeping the single quote in the json and removing the single quotes in the methods below (line 148 and 162 GeofencePlugin.swift) fix the issue

`

`

`

`