diff --git a/main/webapp/modules/core/scripts/dialogs/custom-tabular-exporter-dialog.js b/main/webapp/modules/core/scripts/dialogs/custom-tabular-exporter-dialog.js index 11484b9ed..5211c4a18 100644 --- a/main/webapp/modules/core/scripts/dialogs/custom-tabular-exporter-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/custom-tabular-exporter-dialog.js @@ -34,8 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. function CustomTabularExporterDialog(options) { options = options || { format: 'tsv', - lineSeparator: '\\n', - separator: '\\t', + lineSeparator: '\n', + separator: '\t', encoding: 'UTF-8', outputColumnHeaders: true, outputBlankRows: false, @@ -201,9 +201,12 @@ CustomTabularExporterDialog.prototype._createDialog = function(options) { }; CustomTabularExporterDialog.prototype._configureUIFromOptionCode = function(options) { + var escapeJavascriptString = function(s) { + return JSON.stringify([s]).replace(/^\[\s*"/, '').replace(/"\s*]$/, ''); + }; this._dialog.find('input[name="custom-tabular-exporter-download-format"][value="' + options.format + '"]').attr('checked', 'checked'); - this._elmts.separatorInput[0].value = options.separator || ','; - this._elmts.lineSeparatorInput[0].value = options.lineSeparator || '\\n'; + this._elmts.separatorInput[0].value = escapeJavascriptString(options.separator || ','); + this._elmts.lineSeparatorInput[0].value = escapeJavascriptString(options.lineSeparator || '\n'); this._elmts.encodingInput[0].value = options.encoding; this._elmts.outputColumnHeadersCheckbox.attr('checked', (options.outputColumnHeaders) ? 'checked' : ''); this._elmts.outputBlankRowsCheckbox.attr('checked', (options.outputBlankRows) ? 'checked' : ''); @@ -333,16 +336,23 @@ CustomTabularExporterDialog.prototype._getOptionCode = function() { var options = { format: this._dialog.find('input[name="custom-tabular-exporter-download-format"]:checked').val() }; - + var unescapeJavascriptString = function(s) { + try { + return JSON.parse('"' + s + '"'); + } catch (e) { + // We're not handling the case where the user doesn't escape double quotation marks. + return s; + } + }; if (options.format == 'tsv' || options.format == 'csv' || options.format == '*sv') { if (options.format == 'tsv') { - options.separator = '\\t'; + options.separator = '\t'; } else if (options.format == 'csv') { options.separator = ','; } else { - options.separator = this._elmts.separatorInput.val(); + options.separator = unescapeJavascriptString(this._elmts.separatorInput.val()); } - options.lineSeparator = this._elmts.lineSeparatorInput.val(); + options.lineSeparator = unescapeJavascriptString(this._elmts.lineSeparatorInput.val()); options.encoding = this._elmts.encodingInput.val(); } options.outputColumnHeaders = this._elmts.outputColumnHeadersCheckbox[0].checked;