diff --git a/geoserverexplorer/gui/gsnameutils.py b/geoserverexplorer/gui/gsnameutils.py index 37bb062..837bb84 100644 --- a/geoserverexplorer/gui/gsnameutils.py +++ b/geoserverexplorer/gui/gsnameutils.py @@ -24,8 +24,10 @@ # noinspection PyPep8Naming def xmlNameFixUp(name): - # TODO: handle bad unicode characters, too - n = name.replace(u' ', u'_') # doesn't hurt to always do this + if not isinstance(name, unicode): + name = name.decode('utf-8', errors='ignore') + n = unicode(unicodedata.normalize('NFKD', name).encode('ascii','ignore')) + n = re.sub('[ /\\\\]', '_', n) if not xmlNameIsValid(n) and not n.startswith(u'_'): rx = QRegExp(r'^(?=XML|\d|\W).*', Qt.CaseInsensitive) if rx.exactMatch(n): diff --git a/geoserverexplorer/qgis/catalog.py b/geoserverexplorer/qgis/catalog.py index 06069c6..2060513 100644 --- a/geoserverexplorer/qgis/catalog.py +++ b/geoserverexplorer/qgis/catalog.py @@ -134,8 +134,9 @@ def publishStyle(self, layer, overwrite = True, name = None): layer = layers.resolveLayer(layer) sld, icons = getGsCompatibleSld(layer) if sld is not None: - name = name if name is not None else layer.name() - name = name.replace(" ", "_") + name = name if name is not None else xmlNameFixUp(layer.name()) + if layer.name() != name: + sld = sld.replace(layer.name(), name) self.uploadIcons(icons) self.catalog.create_style(name, sld, overwrite) return sld