Skip to content

Commit

Permalink
Fix percent char handling in property names
Browse files Browse the repository at this point in the history
Previously we executed 'decodeURIComponent' on each path segment. This lead to
errors when an actual URI special character was encountered. As there is no reason for
JSON Forms to transform paths with 'decodeURIComponent' this code was removed
and thereby the error fixed.

Fixes #2119
  • Loading branch information
TheZoker committed Apr 14, 2023
1 parent ba35fde commit 5bcb632
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/core/src/util/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const resolveData = (instance: any, dataPath: string): any => {
const dataPathSegments = dataPath.split('.');

return dataPathSegments
.map(segment => decodeURIComponent(segment))
.reduce((curInstance, decodedSegment) => {
if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
return undefined;
Expand Down
6 changes: 0 additions & 6 deletions packages/core/test/util/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ test('resolve instance with keywords', t => {
const result = Resolve.data(instance, toDataPath('#/properties/properties'));
t.is(result, 123);
});
test('resolve instance with encoded', t => {
const instance = { 'foo/bar': 123 };
const fooBar = encodeURIComponent('foo/bar');
const result = Resolve.data(instance, toDataPath(`#/properties/${fooBar}`));
t.is(result, 123);
});
test('resolve nested instance', t => {
const instance = { foo: { bar: 123 } };
const result = Resolve.data(
Expand Down
10 changes: 9 additions & 1 deletion packages/core/test/util/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { resolveSchema } from '../../src/util/resolvers';
import { resolveData, resolveSchema } from '../../src/util/resolvers';
import test from 'ava';

test('resolveSchema - resolves schema with any ', t => {
Expand Down Expand Up @@ -155,3 +155,11 @@ test('resolveSchema - resolves schema with encoded characters', t => {
t.deepEqual(resolveSchema(schema, '#/properties/foo ~1 ~0 bar', schema), {type: 'integer'});
t.is(resolveSchema(schema, '#/properties/foo / bar', schema), undefined);
});


test('resolveData - resolves data with % characters', t => {
const data = {
'foo%': '123'
};
t.deepEqual(resolveData(data, 'foo%'), '123');
});

0 comments on commit 5bcb632

Please sign in to comment.