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
|
# Dependency directory
|
||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/npm-debug.log
|
||||||
|
|
||||||
/tmp/
|
/tmp/
|
||||||
/src/js/index.js
|
/src/js/index.js
|
||||||
|
|||||||
@@ -162,9 +162,10 @@ Clay.prototype.generateUrl = function() {
|
|||||||
Clay.prototype.getSettings = function(response, convert) {
|
Clay.prototype.getSettings = function(response, convert) {
|
||||||
// Decode and parse config data as JSON
|
// Decode and parse config data as JSON
|
||||||
var settings = {};
|
var settings = {};
|
||||||
|
response = response.match(/^\{/) ? response : decodeURIComponent(response);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
settings = JSON.parse(decodeURIComponent(response));
|
settings = JSON.parse(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('The provided response was not valid JSON');
|
throw new Error('The provided response was not valid JSON');
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -239,7 +239,7 @@ describe('Clay', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('.getSettings', 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() {
|
function() {
|
||||||
var clay = fixture.clay([]);
|
var clay = fixture.clay([]);
|
||||||
var settings = encodeURIComponent(JSON.stringify({
|
var settings = encodeURIComponent(JSON.stringify({
|
||||||
@@ -255,6 +255,22 @@ describe('Clay', function() {
|
|||||||
assert.deepEqual(result, expected);
|
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',
|
it('does not store the response if it is invalid JSON and logs an error',
|
||||||
function() {
|
function() {
|
||||||
var clay = fixture.clay([]);
|
var clay = fixture.clay([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user