]> git.joonet.de Git - adminer.git/commitdiff
Improve enum parsing
authorJakub Vrana <jakub@vrana.cz>
Sun, 6 May 2018 17:14:54 +0000 (19:14 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 6 May 2018 17:21:58 +0000 (19:21 +0200)
adminer/static/editing.js

index 6a172496df05809f6587b7155196e00ddce0fbe1..dd5812f42db8e31e81661aabda8ddf50370a42fe 100644 (file)
@@ -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
 */