Skip to content

Commit

Permalink
Fix to not link nodes outside baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
datakurre committed Jul 25, 2019
1 parent abfe073 commit e26b7f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/__tests__/utils.tests.js
Expand Up @@ -213,13 +213,16 @@ test('normalizeData maps @id to _id and _path', async () => {

test('normalizeData prefixes id, parent and children with _', async () => {
expect(
normalizeData({
id: '',
parent: {
'@id': 'http://localhost:8080/Plone',
normalizeData(
{
id: '',
parent: {
'@id': 'http://localhost:8080/Plone',
},
children: [],
},
children: [],
})
'http://localhost:8080/Plone'
)
).toEqual({
_id: '',
_parent: {
Expand All @@ -231,6 +234,28 @@ test('normalizeData prefixes id, parent and children with _', async () => {
});
});

test('normalizeData excludes node___NODE when @id outside baseUrl', async () => {
expect(
normalizeData(
{
id: '',
parent: {
'@id': 'http://localhost:8080/Foo',
},
children: [],
},
'http://localhost:8080/Plone'
)
).toEqual({
_id: '',
_parent: {
_id: 'http://localhost:8080/Foo',
_path: '/',
},
_children: [],
});
});

test('normalizeData drops /view suffix from id', async () => {
expect(
normalizeData(
Expand Down
8 changes: 7 additions & 1 deletion src/utils.js
Expand Up @@ -149,7 +149,13 @@ export const normalizeData = function(data, baseUrl, depth = 0) {
delete data[key];
} else if (key.length && key[0] === '@') {
data['_' + key.slice(1)] = value;
if (key === '@id' && depth > 0 && value.match('@') === null) {
if (
key === '@id' &&
depth > 0 &&
value &&
value.startsWith(baseUrl) &&
value.match('@') === null
) {
data.node___NODE = value;
}
delete data[key];
Expand Down

0 comments on commit e26b7f3

Please sign in to comment.