Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2022.02.xx] Error downloading filtered dataset, where filter is based on another layer (#8603) #8650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions web/client/observables/wps/__tests__/common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import expect from 'expect';

import {
getWPSURL
getWPSURL,
cdata
} from '../common';


Expand Down Expand Up @@ -40,5 +41,63 @@ describe('common WPS utils', () => {
expect(/https:\/\/host.?\/service\/wps\?service=WPS&IDENTIFIER=gs%3AAggregate&REQUEST=DescribeProcess&version=1\.0\.0/.test(getWPSURL(url, options))).toEqual(true);

});

it('test cdata wrapper on xml with no cdata', () => {
const filterString = `<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>`;
expect(cdata(filterString)).toEqual(`<![CDATA[<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>]]>`);
});
it('test cdata wrapper on xml with cdata', () => {
const filterString = `<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
<ogc:Literal>
<![CDATA[INCLUDE]]>
</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>`;
expect(cdata(filterString)).toEqual(filterString);
});
});
8 changes: 7 additions & 1 deletion web/client/observables/wps/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ export const literalData = (literal) => `<wps:LiteralData>${literal}</wps:Litera
export const complexData = (data, mimeType, encoding) => `<wps:ComplexData${mimeType ? ` mimeType="${mimeType}"` : ''}${encoding ? ` encoding="${encoding}"` : ''}>${data}</wps:ComplexData>`;
/**
* Wrap data in CDATA
* Avoids wrapping data if it already contains CDATA
* @memberof observables.wps.common
* @param {string} data data to wrap
* @returns {string}
*/
export const cdata = (data) => `<![CDATA[${data}]]>`;
export const cdata = (data) => {
const regex = /\bCDATA\b/;
const isCdataIncluded = regex.test(data);
if (isCdataIncluded) return data;
return `<![CDATA[${data}]]>`;
};

/**
* Wrap XML in wps:ResponseForm
Expand Down