mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-27 20:36:33 -04:00
Allow response in webviewclosed event to optionally be URI encoded
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
|
||||
/tmp/
|
||||
/src/js/index.js
|
||||
|
||||
@@ -162,9 +162,10 @@ Clay.prototype.generateUrl = function() {
|
||||
Clay.prototype.getSettings = function(response, convert) {
|
||||
// Decode and parse config data as JSON
|
||||
var settings = {};
|
||||
response = response.match(/^\{/) ? response : decodeURIComponent(response);
|
||||
|
||||
try {
|
||||
settings = JSON.parse(decodeURIComponent(response));
|
||||
settings = JSON.parse(response);
|
||||
} catch (e) {
|
||||
throw new Error('The provided response was not valid JSON');
|
||||
}
|
||||
|
||||
+17
-1
@@ -239,7 +239,7 @@ describe('Clay', function() {
|
||||
});
|
||||
|
||||
describe('.getSettings', function() {
|
||||
it('stores the response to localStorage and returns the decoded data',
|
||||
it('it writes to localStorage and returns the data when input is encoded',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = encodeURIComponent(JSON.stringify({
|
||||
@@ -255,6 +255,22 @@ describe('Clay', function() {
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
|
||||
it('it writes to localStorage and returns the data when input is not encoded',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = JSON.stringify({
|
||||
key1: 'value1',
|
||||
key2: {value: 'value2%7Dbreaks'}
|
||||
});
|
||||
var expected = {
|
||||
key1: 'value1',
|
||||
key2: 'value2%7Dbreaks'
|
||||
};
|
||||
var result = clay.getSettings(settings);
|
||||
assert.equal(localStorage.getItem('clay-settings'), JSON.stringify(expected));
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
|
||||
it('does not store the response if it is invalid JSON and logs an error',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
|
||||
Reference in New Issue
Block a user