Preserve international characters in project/file names on import/export (#2720)

* Preserve international characters on import/export

Fixes #1352. Preserve non-ASCII characters in project names on
project creation and filenames on export.

Uses existing filename cleaner with the addition of a few
more characters from StackOverflow, plus "#" which messes
up the download URL. Also URIencode download URL.

Removes unused I18N-incompatible cleaning function from
Wikidata extension rather than fixing it.

* Use common name cleaner function

Also preview cleaned table name instead of raw name, so user can see it.
Also add a TODO for better preview of column names
This commit is contained in:
Tom Morris 2020-06-18 16:06:46 -04:00 committed by GitHub
parent 7793ffbbe9
commit f88c0e3657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 16 deletions

View File

@ -32,11 +32,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var SchemaAlignment = {};
SchemaAlignment._cleanName = function(s) {
return s.replace(/\W/g, " ").replace(/\s+/g, " ").toLowerCase();
};
var SchemaAlignmentDialog = {};
/**

View File

@ -295,7 +295,7 @@ function SqlExporterDialog(options) {
SqlExporterDialog.prototype._configureUIFromOptionCode = function(options) {
this._elmts.tableNameTextBox.val(theProject.metadata.name);
this._elmts.tableNameTextBox.val(theProject.metadata.name.replace(/\W/g, ' ').replace(/\s+/g, '_'));
this._elmts.sqlExportOutputEmptyRowsCheckbox.attr('checked', 'checked');
this._elmts.sqlExportTrimAllColumnsCheckbox.attr('checked', 'checked');
this._elmts.nullCellValueToEmptyStringLabel.attr('checked', 'checked');
@ -334,8 +334,8 @@ function SqlExporterDialog(options) {
return false;
}
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
var format = options.format;
var encoding = options.encoding;
@ -373,7 +373,7 @@ function SqlExporterDialog(options) {
};
SqlExporterDialog.prototype._prepareSqlExportRowsForm = function(format, includeEngine, ext) {
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
var form = document.createElement("form");
$(form)
.css("display", "none")
@ -453,6 +453,7 @@ function SqlExporterDialog(options) {
var self = this;
this._elmts.columnListTable.find('.sql-exporter-dialog-row').each(function() {
if ($(this).find('input[type="checkbox"]')[0].checked) {
// TODO: Ideally we'd like to let the user preview the names in their cleaned SQL-legal form
var name = this.getAttribute('column');
var rowIndex = this.getAttribute('rowIndex');

View File

@ -143,7 +143,7 @@ TemplatingExporterDialog.prototype._updatePreview = function() {
};
TemplatingExporterDialog.prototype._export = function() {
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
var form = document.createElement("form");
$(form)
.css("display", "none")
@ -173,4 +173,4 @@ TemplatingExporterDialog.prototype._export = function() {
form.submit();
document.body.removeChild(form);
};
};

View File

@ -60,7 +60,7 @@ Refine.DefaultImportingController.prototype._showParsingPanel = function(hasFile
if (!(this._projectName) && this._job.config.fileSelection.length > 0) {
var index = this._job.config.fileSelection[0];
var record = this._job.config.retrievalRecord.files[index];
this._projectName = $.trim(record.fileName.replace(/\W/g, ' ').replace(/\s+/g, ' '));
this._projectName = $.trim(record.fileName.replace(/[\._-]/g, ' ').replace(/\s+/g, ' '));
}
if (this._projectName) {
this._parsingPanelElmts.projectNameInput[0].value = this._projectName;

View File

@ -105,8 +105,9 @@ ExporterManager.prototype._initializeUI = function() {
};
ExporterManager.stripNonFileChars = function(name) {
//prohibited characters in file name of linux (/) and windows (\/:*?"<>|)
return $.trim(name.replace(/[\\*\/:?"<>|]/g, ' ')).replace(/\s+/g, '-');
// prohibited characters in file name of linux (/) and windows (\/:*?"<>|)
// and MacOS https://stackoverflow.com/a/47455094/167425
return $.trim(name.replace(/[\\*\/:;,?"<>|#]/g, ' ')).replace(/\s+/g, '-');
};
ExporterManager.handlers.exportRows = function(format, ext) {
@ -121,7 +122,7 @@ ExporterManager.handlers.exportRows = function(format, ext) {
};
ExporterManager.prepareExportRowsForm = function(format, includeEngine, ext) {
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
var name = encodeURI(ExporterManager.stripNonFileChars(theProject.metadata.name));
var form = document.createElement("form");
$(form)
.css("display", "none")
@ -151,7 +152,7 @@ ExporterManager.prepareExportRowsForm = function(format, includeEngine, ext) {
};
ExporterManager.handlers.exportProjectToLocal = function() {
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
var name = encodeURI(ExporterManager.stripNonFileChars(theProject.metadata.name));
var form = document.createElement("form");
$(form)
.css("display", "none")