From 659c34f7c59fe98566c06ddf19df940f213525b6 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 6 May 2018 19:14:54 +0200 Subject: [PATCH] Improve enum parsing --- adminer/static/editing.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 */