Esri / offline-editor-js

ArcGIS JavaScript library for handling offline editing and tiling.
http://esri.github.io/offline-editor-js/demo/
Apache License 2.0
159 stars 142 forks source link

Offline applyEdits breaks with "&" in data #473

Closed flyinb closed 8 years ago

flyinb commented 8 years ago

When online, edits are applied normally, however in offline mode, if an attribute has an "&" symbol in the data, the JSON breaks before it hits the server.

andygup commented 8 years ago

@flyinb can you please provide a console.log stack trace?

flyinb commented 8 years ago

It doesn't produce a console error, the posed JSON data is broken. You can reproduce the error by putting an "&" in an attribute field, going offline (queue edit in offline local database), then going online. The data gets posted, but anywhere there is an "&" symbol, the JSON thinks it's a new posted variable, and not part of a string.

flyinb commented 8 years ago

I fixed it by URI encoding

encodeURIComponent(property);

but as i said before, online works fine, it's only offline edits

flyinb commented 8 years ago

it has knock on effects (I have to decode via an interceptor) Uri.UnescapeDataString(HttpUtility.UrlDecode(att.Value.ToString()));

but i shouldn't have to do this!

andygup commented 8 years ago

There is a console error: EDIT REQUEST RESPONSE WAS NOT SUCCESSFUL: {"error":{"code":400,"message":"Cannot perform operation. Invalid operation parameters.","details":["'updates' parameter is invalid","Unterminated string passed in.

This error makes sense because the library doesn't do any encoding when it overrides returning edits after an offline event. Reference OfflineEditAdvanced.js Line 2010

I'll take a stab at adding encoding. This is a minor enhancement if it works, and then this library will be in compliance with the JS API v3.x.

andygup commented 8 years ago

@flyinb this will be fixed in v3.3.0. I'll push the build in just a few minutes. Let me know if you have any other problems with it.

andygup commented 8 years ago

Reference fix: https://github.com/Esri/offline-editor-js/commit/7dee7b03f682dc795b71eff978ff098bcf80b5ee

flyinb commented 8 years ago

thanks. :)

flyinb commented 8 years ago

arcgis-3.14.min.js:144 Uncaught TypeError: Cannot read property 'setAttribute' of nullb.set @ arcgis-3.14.min.js:144(anonymous function) @ /Scripts/esri/offline-edit-src.js:943transaction.oncomplete @ /Scripts/esri/offline-edit-src.js:2537 /Scripts/esri/offline-edit-src.js:512 All edits done

DIT REQUEST REPONSE WAS NOT SUCCESSFUL: XMLHttpRequest {headers: Object, onreadystatechange: null, readyState: 4, timeout: 15000, withCredentials: false…}headers: Objectonabort: nullonerror: (e)onload: ()onloadend: nullonloadstart: nullonprogress: nullonreadystatechange: nullontimeout: ()open: (type, url, async, user, password)overrideMimeType: (type)readyState: 4response: "{"error":{"code":500,"message":"Unable to complete operation.","details":["No edits ('adds', 'updates' or 'deletes') were specified."]}}"responseText: "{"error":{"code":500,"message":"Unable to complete operation.","details":["No edits ('adds', 'updates' or 'deletes') were specified."]}}"responseType: ""responseURL: "https://gisweb.tauranga.govt.nz/arcgis/rest/services/TreeApp/TreeCapture_AllMaintainenceAreas/FeatureServer/1/applyEdits"responseXML: nullsetRequestHeader: (name, value)status: 200statusText: "OK"timeout: 15000upload: XMLHttpRequestUploadwithCredentials: falseproto: XMLHttpRequestreq.onload @ /Scripts/esri/offline-edit-src.js:2186 /Scripts/esri/offline-edit-src.js:1782 OfflineFeaturesManager._replayStoredEdits - ERROR!!

andygup commented 8 years ago

1) What action caused this error? Is there any way to reproduce it?

2) The error refers to a file named offline-edit-src.js at line 2537. There isn't a file with that name in this repo. Is this a custom file that you created?

3) What version and which library(s) from this repo are you using?

4) Please provide a complete copy of both the entire HTTP REQUEST HEADER and the HTTP RESPONSE. You can get this info from Chrome Developer tools in the Network tab or by using a debug proxy such as Charles, Fiddler or WireShark. A 500 error is an error in the server logic and may have nothing to do with the client app.

Here's an example of what I need:

REQUEST HEADER image

HTTP RESPONSE

{"addResults":[],"updateResults":[{"objectId":20762,"globalId":null,"success":true}],"deleteResults":[]}

flyinb commented 8 years ago

Dang, it appears the previous dev has made his own Angular version of your offline-edit script. Our bad, sorry. I'll take a look at your change, and see if i can inject it. :/

andygup commented 8 years ago

Ah, oops. I'll disregard unless you find something specific to the main library.