[ https://issues.apache.org/jira/browse/CB-6657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13993005#comment-13993005 ]
Shazron Abdullah commented on CB-6657: -------------------------------------- Regex to capture the fields object as the first capture group: {code} {(?:\r|\n|.)+fields:(?:\r|\n|.)+({(?:\r|\n|.)+}),(?:\r|\n|.)+files:(?:\r|\n|.)+ {code} This statement matches all characters including newlines: {code} (?:\r|\n|.)+ {code} test using: http://regexpal.com/ {code} var response = "received upload: { fields: { value2: 'param', value1: 'test' }, files: { file: { domain: null, _events: {}, _maxListeners: 10, size: 24, path: '/opt/run/snapshot/.tmp/063652c9321b9a2cd50672f52d0adc26', name: 'upload.txt', type: 'text/plain', hash: false, lastModifiedDate: Thu May 08 2014 16:21:59 GMT+0000 (UTC), _writeStream: [Object] } } }"; var matches = response.match(/{(?:\r|\n|.)+fields:(?:\r|\n|.)+({(?:\r|\n|.)+}),(?:\r|\n|.)+files:(?:\r|\n|.)+/); var captureGroup1 = matches[1]; console.log("fields object: " + captureGroup1); //var fields = eval("(" + captureGroup1 + ")"); var fields = JSON.parse(captureGroup1); console.log("value1: " + fields.value1); console.log("value2: " + fields.value2); {code} BUT! The json parse still fails because the property names are not double quoted, and we would have to use eval, which is bad. To be a complete solution, we will have to fix the server.js: https://github.com/apache/cordova-labs/blob/44dba1b5b86c1312bb1604202594368474bafc53/server.js#L55 As well as the test. > 3 FileTransfer tests have false negatives > ----------------------------------------- > > Key: CB-6657 > URL: https://issues.apache.org/jira/browse/CB-6657 > Project: Apache Cordova > Issue Type: Bug > Components: mobile-spec > Environment: iOS > Reporter: Shazron Abdullah > > {code} > FileTransfer upload method filetransfer.spec.18 should be able to upload a > file. > Expected 'received upload: { fields: { value2: 'param', value1: 'test' }, > files: { file: { domain: null, _events: {}, _maxListeners: 10, size: 24, > path: '/opt/run/snapshot/.tmp/063652c9321b9a2cd50672f52d0adc26', name: > 'upload.txt', type: 'text/plain', hash: false, lastModifiedDate: Thu May 08 > 2014 16:21:59 GMT+0000 (UTC), _writeStream: [Object] } } } ' to match > /fields:\s*{\s*value1.*/. > FileTransfer upload method filetransfer.spec.19 should be able to upload a > file with http basic auth. > Expected 'received upload: { fields: { value2: 'param', value1: 'test' }, > files: { file: { domain: null, _events: {}, _maxListeners: 10, size: 24, > path: '/opt/run/snapshot/.tmp/4dff830d6b803401635cfcdfc911b739', name: > 'upload.txt', type: 'text/plain', hash: false, lastModifiedDate: Thu May 08 > 2014 16:22:00 GMT+0000 (UTC), _writeStream: [Object] } } } ' to match > /fields:\s*{\s*value1.*/. > FileTransfer Backwards compatibility filetransfer.spec.29 should be able to > upload a file using local paths. > Expected 'received upload: { fields: { value2: 'param', value1: 'test' }, > files: { file: { domain: null, _events: {}, _maxListeners: 10, size: 24, > path: '/opt/run/snapshot/.tmp/4d10d1826c6b8307bc382f8217ea6a10', name: > 'upload.txt', type: 'text/plain', hash: false, lastModifiedDate: Thu May 08 > 2014 16:22:01 GMT+0000 (UTC), _writeStream: [Object] } } } ' to match > /fields:\s*{\s*value1.*/. > {code} > The false negatives are from a regex assumption that the first item in the > fields object is "value1". Since the test server now outputs "value2" as the > first item, the regex fails. > The simple fix is to update the regex so that this passes, but that will not > hold up to future changes of the output by the server. > The better fix is to actually convert the result back to JSON, and test for > the property and/or properties. -- This message was sent by Atlassian JIRA (v6.2#6252)