Skip to content

Commit b785969

Browse files
committed
Merge pull request #513 from jmerrifield/do-not-unescape-view-options
Don't unescape view options Reviewed by @saponifi3d
2 parents 554984e + b9d369c commit b785969

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

shared/base/view.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,14 @@ BaseView.createChildView = function (ViewClass, options, $el, parentView, cb) {
464464
};
465465

466466
BaseView.getViewOptions = function ($el) {
467-
var parsed,
468-
options = $el.data();
467+
var options = $el.data();
469468

470469
_.each(options, function(value, key) {
471470
if (_.isString(value)) {
472-
parsed = _.unescape(value);
473471
try {
474-
parsed = JSON.parse(parsed);
472+
value = JSON.parse(value);
475473
} catch (err) {}
476-
options[key] = parsed;
474+
options[key] = value;
477475
}
478476
});
479477

test/shared/base/view.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -787,4 +787,26 @@ describe('BaseView', function() {
787787
expect(newChildView).to.be.an.instanceOf(ViewClass);
788788
});
789789
});
790+
791+
describe('BaseView.getViewOptions', function() {
792+
it('should not unescape escaped data', function() {
793+
var fakeEl = {
794+
data: _.constant({
795+
normalOption: 'Normal data',
796+
jsonOption: '{"json":"data"}',
797+
escapedOption: 'I am <span>escaped</span>',
798+
escapedJsonOption: '{"escapedData":"I am <span>escaped</span>"}'
799+
})
800+
}
801+
802+
var parsedOptions = BaseView.getViewOptions(fakeEl);
803+
804+
expect(parsedOptions).to.deep.equal({
805+
normalOption: 'Normal data',
806+
jsonOption: {json: 'data'},
807+
escapedOption: 'I am <span>escaped</span>',
808+
escapedJsonOption: {escapedData: 'I am <span>escaped</span>'}
809+
});
810+
});
811+
});
790812
});

0 commit comments

Comments
 (0)