From: Jakub Vrana Date: Sun, 6 May 2018 17:14:54 +0000 (+0200) Subject: Improve enum parsing X-Git-Tag: v4.6.3~13 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=659c34f7c59fe98566c06ddf19df940f213525b6;p=adminer.git Improve enum parsing --- diff --git a/adminer/static/editing.js b/adminer/static/editing.js index 6a172496..dd5812f4 100644 --- a/adminer/static/editing.js +++ b/adminer/static/editing.js @@ -395,8 +395,7 @@ function editingLengthFocus() { var td = this.parentNode; if (/(enum|set)$/.test(selectValue(td.previousSibling.firstChild))) { var edit = qs('#enum-edit'); - var val = this.value; - edit.value = (/^'.+'$/.test(val) ? val.substr(1, val.length - 2).replace(/','/g, "\n").replace(/''/g, "'") : val); //! doesn't handle 'a'',''b' correctly + edit.value = enumValues(this.value); td.appendChild(edit); this.style.display = 'none'; edit.style.display = 'inline'; @@ -404,6 +403,25 @@ function editingLengthFocus() { } } +/** Get enum values +* @param string +* @return string values separated by newlines +*/ +function enumValues(s) { + var re = /(^|,)\s*'(([^\\']|\\.|'')*)'\s*/g; + var result = []; + var offset = 0; + var match; + while (match = re.exec(s)) { + if (offset != match.index) { + break; + } + result.push(match[2].replace(/'(')|\\(.)/g, '$1$2')); + offset += match[0].length; + } + return (offset == s.length ? result.join('\n') : s); +} + /** Finish editing of enum or set * @this HTMLTextAreaElement */