Fixed bug in custom tabular exporter where separators were not escaped/unescaped properly.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2386 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
f1b567bc31
commit
2ad885d6df
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user