Commit 5cd90ef9 authored by Clement Ho's avatar Clement Ho

Add escaping for milestone values

parent da8ab2bc
......@@ -12,21 +12,8 @@
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
if (!dataValueSet) {
let labelTitle = e.detail.selected.querySelector('.label-title').innerText.trim();
// Encapsulate label with quotes if it has spaces
if (labelTitle.indexOf(' ') !== -1) {
if (labelTitle.indexOf('"') !== -1) {
// Use single quotes if label title contains double quotes
labelTitle = `'${labelTitle}'`;
} else {
// Known side effect: Label's with both single and double quotes
// won't escape properly
labelTitle = `"${labelTitle}"`;
}
}
const labelName = `~${labelTitle}`;
const labelTitle = e.detail.selected.querySelector('.label-title').innerText.trim();
const labelName = `~${this.getEscapedText(labelTitle)}`;
gl.FilteredSearchManager.addWordToInput(labelName);
}
......
......@@ -12,7 +12,8 @@
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
if (!dataValueSet) {
const milestoneName = `%${e.detail.selected.querySelector('.btn-link').innerText.trim()}`;
const milestoneTitle = e.detail.selected.querySelector('.btn-link').innerText.trim();
const milestoneName = `%${this.getEscapedText(milestoneTitle)}`;
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(milestoneName));
}
......
......@@ -18,6 +18,24 @@
this.dropdown.removeEventListener('click.dl', this.itemClicked.bind(this));
}
getEscapedText(text) {
let escapedText = text;
// Encapsulate value with quotes if it has spaces
if (text.indexOf(' ') !== -1) {
if (text.indexOf('"') !== -1) {
// Use single quotes if value contains double quotes
escapedText = `'${text}'`;
} else {
// Known side effect: values's with both single and double quotes
// won't escape properly
escapedText = `"${text}"`;
}
}
return escapedText;
}
getSelectedText(selectedToken) {
// TODO: Get last word from FilteredSearchTokenizer
const lastWord = this.input.value.split(' ').last();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment