Skip to content

Commit

Permalink
Prevent RequestNotWellFormed error for invalid characters in BBOX r…
Browse files Browse the repository at this point in the history
…equests (ref: layer names with spaces, colons or slashes) (#566)

* 🐛 Use regex that substitute only blanck space with underscore

* 🐛 Use regex that substitute only blanck space with underscore and replace / with no space

* 🐛 Fix filter SELECTED layers. Fix bug on query bypolygon. It returned features of selected layer. Wrong

* In case of wfs request, need to take in account replace of / and : on layer Name

* make use of `has(filter.SELECTED)`

* inline replacer

* variable name

* wrong param

* micro perf opts

* variable name

* Remove layerName. Not translate. useless

* Take in account drawpolygon query type

* Update src/app/core/layers/imagelayer.js

replace all : with - using replaceAll string method

Co-authored-by: Raruto <Raruto@users.noreply.github.com>

* Remove plus regex.

* Sanitize also / slash

* remove console.log

---------

Co-authored-by: Raruto <Raruto@users.noreply.github.com>
  • Loading branch information
volterra79 and Raruto authored Feb 7, 2024
1 parent 56ba2d2 commit 7126f24
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/app/core/layers/imagelayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ proto.getWmsUrl = function({ type = 'map' } = {}) {
return this.config.wmsUrl;
};

proto.getWFSLayerName = function(){
return this.getQueryLayerName().replace(/[/\s]/g, '_')
proto.getWFSLayerName = function() {
return this.getQueryLayerName().replace(/\s/g, '_').replaceAll( ':', '-' );
};

proto.useProxy = function(){
Expand Down
40 changes: 19 additions & 21 deletions src/app/core/layers/layersstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proto.getLayersDict = function(filter = {}, options = {}) {
filter.FILTERABLE,
filter.EDITABLE,
filter.VISIBLE,
// filter.SELECTED,
filter.SELECTED,
filter.CACHED,
filter.SELECTED_OR_ALL,
filter.SERVERTYPE,
Expand All @@ -109,33 +109,31 @@ proto.getLayersDict = function(filter = {}, options = {}) {

if (filter.IDS) {
const ids = [].concat(filter.IDS);
layers = layers.filter(layer => -1 !== ids.indexOf(layer.getId()));
layers = layers.filter(l => -1 !== ids.indexOf(l.getId()));
}

// return only selected if some one are selected
// check if there are `selected` layers otherwise get all `layers`
if (filter.SELECTED_OR_ALL) {
let _layers = layers;
layers = layers.filter(layer => layer.isSelected());
layers = layers.length ? layers : _layers;
} else if (false === filter.SELECTED_OR_ALL) {
layers = layers.filter(layer => filter.SELECTED === layer.isSelected());
const selected = layers.filter(l => l.isSelected());
layers = selected.length > 0 ? selected : layers;
}

// checks if a boolean filter is setted
const has = f => 'boolean' === typeof f;

if (has(filter.QUERYABLE)) layers = layers.filter(layer => filter.QUERYABLE === layer.isQueryable());
if (has(filter.FILTERABLE)) layers = layers.filter(layer => filter.FILTERABLE === layer.isFilterable(options.filtrable || null));
if (has(filter.EDITABLE)) layers = layers.filter(layer => filter.EDITABLE === layer.isEditable());
if (has(filter.VISIBLE)) layers = layers.filter(layer => filter.VISIBLE === layer.isVisible());
if (has(filter.CACHED)) layers = layers.filter(layer => filter.CACHED === layer.isCached());
if (has(filter.BASELAYER)) layers = layers.filter(layer => filter.BASELAYER === layer.isBaseLayer());
if (has(filter.GEOLAYER)) layers = layers.filter(layer => filter.GEOLAYER === layer.state.geolayer);
if (has(filter.VECTORLAYER)) layers = layers.filter(layer => filter.VECTORLAYER === layer.isType('vector'));
if (has(filter.HIDDEN)) layers = layers.filter(layer => filter.HIDDEN == layer.isHidden());
if (has(filter.DISABLED)) layers = layers.filter(layer => filter.DISABLED === layer.isDisabled());
if ('string' === typeof filter.SERVERTYPE && filter.SERVERTYPE.length) layers = layers.filter(layer => filter.SERVERTYPE === layer.getServerType());
if (filter.PRINTABLE) layers = layers.filter(layer => layer.state.geolayer && layer.isPrintable({ scale: filter.PRINTABLE.scale }));

if (has(filter.SELECTED) && !filter.SELECTED_OR_ALL) layers = layers.filter(l => filter.SELECTED === l.isSelected());
if (has(filter.QUERYABLE)) layers = layers.filter(l => filter.QUERYABLE === l.isQueryable());
if (has(filter.FILTERABLE)) layers = layers.filter(l => filter.FILTERABLE === l.isFilterable(options.filtrable || null));
if (has(filter.EDITABLE)) layers = layers.filter(l => filter.EDITABLE === l.isEditable());
if (has(filter.VISIBLE)) layers = layers.filter(l => filter.VISIBLE === l.isVisible());
if (has(filter.CACHED)) layers = layers.filter(l => filter.CACHED === l.isCached());
if (has(filter.BASELAYER)) layers = layers.filter(l => filter.BASELAYER === l.isBaseLayer());
if (has(filter.GEOLAYER)) layers = layers.filter(l => filter.GEOLAYER === l.state.geolayer);
if (has(filter.VECTORLAYER)) layers = layers.filter(l => filter.VECTORLAYER === l.isType('vector'));
if (has(filter.HIDDEN)) layers = layers.filter(l => filter.HIDDEN == l.isHidden());
if (has(filter.DISABLED)) layers = layers.filter(l => filter.DISABLED === l.isDisabled());
if ('string' === typeof filter.SERVERTYPE && filter.SERVERTYPE.length) layers = layers.filter(l => filter.SERVERTYPE === l.getServerType());
if (filter.PRINTABLE) layers = layers.filter(l => l.state.geolayer && l.isPrintable({ scale: filter.PRINTABLE.scale }));

return layers;
};
Expand Down
3 changes: 1 addition & 2 deletions src/app/g3w-ol/controls/querybydrawpolygoncontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ proto.runSpatialQuery = async function() {
try {
await DataRouterService.getData('query:polygon', {
inputs: {
layerName: 'Draw',
feature: this.feature,
excludeSelected: (null === this.getSelectedLayer()),
external: {
Expand All @@ -177,7 +176,7 @@ proto.runSpatialQuery = async function() {
}
});

} catch(err){
} catch(err) {
console.warn(err)
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/app/gui/queryresults/queryresultsservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2316,7 +2316,8 @@ QueryResultsService.prototype.setters = {
switch (this.state.query.type) {
case 'coordinates': this.showCoordinates(this.state.query.coordinates); break;
case 'bbox': this.showBBOX(this.state.query.bbox); break;
case 'polygon': this.showGeometry(this.state.query.geometry); break;
case 'polygon':
case 'drawpolygon': this.showGeometry(this.state.query.geometry); break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/QueryResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
message: ` [${query.bbox.join(' , ')}]`
};
case 'polygon':
case 'drawpolygon':
return {
icon: 'draw',
message: (query.layerName) ?
Expand Down
15 changes: 10 additions & 5 deletions src/utils/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,20 @@ const utils = {
},
handleXMLStringResponseBeforeConvertToJSON({response, layers, wms}={}) {
if (!response) return; // return undefined if no response
if (!(typeof response === 'string'|| response instanceof String))
if (!(typeof response === 'string'|| response instanceof String)) {
response = new XMLSerializer().serializeToString(response);
}
for (let i=0; i < layers.length; i++) {
const layer = layers[i];
let originalName = (wms && layer.isWmsUseLayerIds()) ? layer.getId(): layer.getName();
let sanitizeLayerName = wms ? originalName.replace(/[/\s]/g, '') : originalName.replace(/[/\s]/g, '_');
sanitizeLayerName = sanitizeLayerName.replace(/(\'+)/, '');
sanitizeLayerName = sanitizeLayerName.replace(/(\)+)/, '');
sanitizeLayerName = sanitizeLayerName.replace(/(\(+)/, '');
let sanitizeLayerName = wms ? originalName.replace(/[/\s]/g, '') : originalName.replace(/\s/g, '_');
sanitizeLayerName = sanitizeLayerName.replace(/(\'+)/, '');
sanitizeLayerName = sanitizeLayerName.replace(/(\)+)/, '');
sanitizeLayerName = sanitizeLayerName.replace(/(\(+)/, '');
sanitizeLayerName = wms ? sanitizeLayerName : sanitizeLayerName.replace(/\//g, '');
sanitizeLayerName = wms ? sanitizeLayerName : sanitizeLayerName.replace(/\\/g, '');
sanitizeLayerName = wms ? sanitizeLayerName : sanitizeLayerName.replace(/\:/g, '-');

const reg = new RegExp(`qgs:${sanitizeLayerName}`, "g");
response = response.replace(reg, `qgs:layer${i}`);
}
Expand Down

0 comments on commit 7126f24

Please sign in to comment.