A platform for community discussion. Free, open, simple.
FIX: allows forcing unsafe string in select-kit (#6386)
Joffrey JAFFEUX38668818a5ba
diff --git a/app/assets/javascripts/admin/templates/customize-themes-show.hbs b/app/assets/javascripts/admin/templates/customize-themes-show.hbsindex 3ab5bf43ab2..21090a03e92 100644--- a/app/assets/javascripts/admin/templates/customize-themes-show.hbs+++ b/app/assets/javascripts/admin/templates/customize-themes-show.hbs@@ -40,6 +40,7 @@<p>{{i18n "admin.customize.theme.color_scheme_select"}}</p><p>{{combo-box content=colorSchemesfilterable=true+ forceEscape=truevalue=colorSchemeIdicon="paint-brush"}}{{#if colorSchemeChanged}}@@ -142,7 +143,7 @@{{/unless}}{{#if selectableChildThemes}}<p>- {{combo-box filterable=true content=selectableChildThemes value=selectedChildThemeId}}+ {{combo-box forceEscape=true filterable=true content=selectableChildThemes value=selectedChildThemeId}}{{#d-button action="addChildTheme" icon="plus"}}{{i18n "admin.customize.theme.add"}}{{/d-button}}</p>{{/if}}diff --git a/app/assets/javascripts/select-kit/components/list-setting.js.es6 b/app/assets/javascripts/select-kit/components/list-setting.js.es6index 457cc62bba1..6cf37e05897 100644--- a/app/assets/javascripts/select-kit/components/list-setting.js.es6+++ b/app/assets/javascripts/select-kit/components/list-setting.js.es6@@ -17,12 +17,9 @@ export default MultiSelectComponent.extend({}if (this.get("nameProperty").indexOf("color") > -1) {- this.set(- "headerComponentOptions",- Ember.Object.create({- selectedNameComponent: "multi-select/selected-color"- })- );+ this.get("headerComponentOptions").setProperties({+ selectedNameComponent: "multi-select/selected-color"+ });}},diff --git a/app/assets/javascripts/select-kit/components/multi-select.js.es6 b/app/assets/javascripts/select-kit/components/multi-select.js.es6index b2a71ebf88c..79dc0c0f148 100644--- a/app/assets/javascripts/select-kit/components/multi-select.js.es6+++ b/app/assets/javascripts/select-kit/components/multi-select.js.es6@@ -31,12 +31,9 @@ export default SelectKitComponent.extend({this.set("values", []);}- this.set(- "headerComponentOptions",- Ember.Object.create({- selectedNameComponent: this.get("selectedNameComponent")- })- );+ this.get("headerComponentOptions").setProperties({+ selectedNameComponent: this.get("selectedNameComponent")+ });},@on("didRender")diff --git a/app/assets/javascripts/select-kit/components/multi-select/multi-select-header.js.es6 b/app/assets/javascripts/select-kit/components/multi-select/multi-select-header.js.es6index b87881ec5ba..9b82221f005 100644--- a/app/assets/javascripts/select-kit/components/multi-select/multi-select-header.js.es6+++ b/app/assets/javascripts/select-kit/components/multi-select/multi-select-header.js.es6@@ -14,6 +14,8 @@ export default SelectKitHeaderComponent.extend({"select-kit/templates/components/multi-select/multi-select-header",selectedNameComponent: Ember.computed.alias("options.selectedNameComponent"),+ forceEscape: Ember.computed.alias("options.forceEscape"),+ariaLabel: Ember.computed.or("computedContent.ariaLabel", "title", "names"),title: Ember.computed.or("computedContent.title", "names"),diff --git a/app/assets/javascripts/select-kit/components/select-kit.js.es6 b/app/assets/javascripts/select-kit/components/select-kit.js.es6index e490b61ea1b..b69c1d5d049 100644--- a/app/assets/javascripts/select-kit/components/select-kit.js.es6+++ b/app/assets/javascripts/select-kit/components/select-kit.js.es6@@ -81,13 +81,22 @@ export default Ember.Component.extend(minimum: null,minimumLabel: null,maximumLabel: null,+ forceEscape: false,init() {this._super();this.noneValue = "__none__";- this.set("headerComponentOptions", Ember.Object.create());- this.set("rowComponentOptions", Ember.Object.create());+ this.set(+ "headerComponentOptions",+ Ember.Object.create({ forceEscape: this.get("forceEscape") })+ );+ this.set(+ "rowComponentOptions",+ Ember.Object.create({+ forceEscape: this.get("forceEscape")+ })+ );this.set("computedContent", []);this.set("highlightedSelection", []);diff --git a/app/assets/javascripts/select-kit/components/select-kit/select-kit-header.js.es6 b/app/assets/javascripts/select-kit/components/select-kit/select-kit-header.js.es6index 79464c9109b..3253c5d9a27 100644--- a/app/assets/javascripts/select-kit/components/select-kit/select-kit-header.js.es6+++ b/app/assets/javascripts/select-kit/components/select-kit/select-kit-header.js.es6@@ -14,6 +14,8 @@ export default Ember.Component.extend({"name:data-name"],+ forceEscape: Ember.computed.alias("options.forceEscape"),+isNone: Ember.computed.none("computedContent.value"),ariaHasPopup: true,diff --git a/app/assets/javascripts/select-kit/components/select-kit/select-kit-row.js.es6 b/app/assets/javascripts/select-kit/components/select-kit/select-kit-row.js.es6index a289beeccf0..a1c7f6ba4af 100644--- a/app/assets/javascripts/select-kit/components/select-kit/select-kit-row.js.es6+++ b/app/assets/javascripts/select-kit/components/select-kit/select-kit-row.js.es6@@ -18,6 +18,8 @@ export default Ember.Component.extend(UtilsMixin, {],classNameBindings: ["isHighlighted", "isSelected"],+ forceEscape: Ember.computed.alias("options.forceEscape"),+ariaLabel: Ember.computed.or("computedContent.ariaLabel", "title"),@computed("computedContent.title", "name")diff --git a/app/assets/javascripts/select-kit/templates/components/combo-box/combo-box-header.hbs b/app/assets/javascripts/select-kit/templates/components/combo-box/combo-box-header.hbsindex b13075d3f2d..c9fc965ee83 100644--- a/app/assets/javascripts/select-kit/templates/components/combo-box/combo-box-header.hbs+++ b/app/assets/javascripts/select-kit/templates/components/combo-box/combo-box-header.hbs@@ -1,7 +1,11 @@{{#each icons as |icon|}} {{d-icon icon}} {{/each}}<span class="selected-name">- {{{label}}}+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}</span>{{#if shouldDisplayClearableButton}}diff --git a/app/assets/javascripts/select-kit/templates/components/future-date-input-selector/future-date-input-selector-header.hbs b/app/assets/javascripts/select-kit/templates/components/future-date-input-selector/future-date-input-selector-header.hbsindex c566d3b1e5d..a5c5cbd6a36 100644--- a/app/assets/javascripts/select-kit/templates/components/future-date-input-selector/future-date-input-selector-header.hbs+++ b/app/assets/javascripts/select-kit/templates/components/future-date-input-selector/future-date-input-selector-header.hbs@@ -5,7 +5,11 @@{{/if}}<span class="selected-name" title={{title}}>- {{{label}}}+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}</span>{{#if computedContent.datetime}}diff --git a/app/assets/javascripts/select-kit/templates/components/multi-select/multi-select-header.hbs b/app/assets/javascripts/select-kit/templates/components/multi-select/multi-select-header.hbsindex 2627302c4e7..e95d429d27f 100644--- a/app/assets/javascripts/select-kit/templates/components/multi-select/multi-select-header.hbs+++ b/app/assets/javascripts/select-kit/templates/components/multi-select/multi-select-header.hbs@@ -3,6 +3,7 @@{{component selectedNameComponentonClickSelectionItem=onClickSelectionItemhighlightedSelection=highlightedSelection+ forceEscape=forceEscapecomputedContent=selection}}{{/each}}<span class="filter choice" tabindex="-1">diff --git a/app/assets/javascripts/select-kit/templates/components/multi-select/selected-name.hbs b/app/assets/javascripts/select-kit/templates/components/multi-select/selected-name.hbsindex ffa6a8f3b91..141ae2748f6 100644--- a/app/assets/javascripts/select-kit/templates/components/multi-select/selected-name.hbs+++ b/app/assets/javascripts/select-kit/templates/components/multi-select/selected-name.hbs@@ -2,7 +2,11 @@<div class="body"><span class="name">- {{{label}}}+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}</span></div>diff --git a/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-header.hbs b/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-header.hbsindex e65ce13500b..77ea5328166 100644--- a/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-header.hbs+++ b/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-header.hbs@@ -1,5 +1,9 @@{{#each icons as |icon|}} {{d-icon icon}} {{/each}}<span class="selected-name">- {{{label}}}+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}</span>diff --git a/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-row.hbs b/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-row.hbsindex fc0df658357..984d7091516 100644--- a/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-row.hbs+++ b/app/assets/javascripts/select-kit/templates/components/select-kit/select-kit-row.hbs@@ -2,5 +2,11 @@{{{template}}}{{else}}{{#each icons as |icon|}} {{d-icon icon}} {{/each}}- <span class="name">{{{label}}}</span>+ <span class="name">+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}+ </span>{{/if}}diff --git a/app/assets/javascripts/select-kit/templates/components/tag-drop/tag-drop-header.hbs b/app/assets/javascripts/select-kit/templates/components/tag-drop/tag-drop-header.hbsindex 7e3ea1baf4f..440988e3efe 100644--- a/app/assets/javascripts/select-kit/templates/components/tag-drop/tag-drop-header.hbs+++ b/app/assets/javascripts/select-kit/templates/components/tag-drop/tag-drop-header.hbs@@ -1,5 +1,9 @@<span class="selected-name">- {{{label}}}+ {{#if forceEscape}}+ {{label}}+ {{else}}+ {{{label}}}+ {{/if}}</span>{{d-icon caretIcon class="caret-icon fa-fw"}}diff --git a/test/javascripts/components/multi-select-test.js.es6 b/test/javascripts/components/multi-select-test.js.es6index b1f78fdfae0..ea13a619082 100644--- a/test/javascripts/components/multi-select-test.js.es6+++ b/test/javascripts/components/multi-select-test.js.es6@@ -247,3 +247,73 @@ componentTest("with minimumLabel", {);}});++componentTest("with forceEscape", {+ template: "{{multi-select content=content forceEscape=true}}",++ beforeEach() {+ this.set("content", ["<div>sam</div>"]);+ },++ async test(assert) {+ await this.get("subject").expand();++ const row = this.get("subject").rowByIndex(0);+ assert.equal(+ row+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>sam</div>"+ );++ await this.get("subject").fillInFilter("<div>jeff</div>");+ await this.get("subject").keyboard("enter");++ assert.equal(+ this.get("subject")+ .header()+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>jeff</div>"+ );+ }+});++componentTest("with forceEscape", {+ template: "{{multi-select content=content forceEscape=false}}",++ beforeEach() {+ this.set("content", ["<div>sam</div>"]);+ },++ async test(assert) {+ await this.get("subject").expand();++ const row = this.get("subject").rowByIndex(0);+ assert.equal(+ row+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>sam</div>"+ );++ await this.get("subject").fillInFilter("<div>jeff</div>");+ await this.get("subject").keyboard("enter");++ assert.equal(+ this.get("subject")+ .header()+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>jeff</div>"+ );+ }+});diff --git a/test/javascripts/components/single-select-test.js.es6 b/test/javascripts/components/single-select-test.js.es6index 7e6c6158a40..439781e202e 100644--- a/test/javascripts/components/single-select-test.js.es6+++ b/test/javascripts/components/single-select-test.js.es6@@ -771,3 +771,67 @@ componentTest("with no content and allowAny", {assert.ok(!$filter.hasClass("is-hidden"));}});++componentTest("with forceEscape", {+ template: "{{single-select content=content forceEscape=true}}",++ beforeEach() {+ this.set("content", ["<div>sam</div>"]);+ },++ async test(assert) {+ await this.get("subject").expand();++ const row = this.get("subject").rowByIndex(0);+ assert.equal(+ row+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>sam</div>"+ );++ assert.equal(+ this.get("subject")+ .header()+ .el()+ .find(".selected-name")+ .html()+ .trim(),+ "<div>sam</div>"+ );+ }+});++componentTest("without forceEscape", {+ template: "{{single-select content=content forceEscape=false}}",++ beforeEach() {+ this.set("content", ["<div>sam</div>"]);+ },++ async test(assert) {+ await this.get("subject").expand();++ const row = this.get("subject").rowByIndex(0);+ assert.equal(+ row+ .el()+ .find(".name")+ .html()+ .trim(),+ "<div>sam</div>"+ );++ assert.equal(+ this.get("subject")+ .header()+ .el()+ .find(".selected-name")+ .html()+ .trim(),+ "<div>sam</div>"+ );+ }+});