Creating asset via rest is not possible anymore

Description

Steps to reproduce

  1. Use any magnolia instance (for example jumpstart)

  2. Try adding an Asset via rest, like described in the documentation
    https://docs.magnolia-cms.com/product-docs/6.2/Developing/How-to-add-an-asset-with-REST.html

Expected results

It should be possible to add Assets via rest

Actual results

The Asset is not added properly because the jcr:content node of the asset is saved as jcr-content.

Workaround

Development notes

I think the problem could maybe come with this commit from the latest version:

https://git.magnolia-cms.com/projects/MODULES/repos/rest/commits/f9cd00ffd4349e62cb9e8ede62bf01bc1648381c#magnolia-rest-services/src/main/java/info/magnolia/rest/service/node/v1/NodeEndpoint.java

Because the colon is now an invalid character, jcr:content is saved as jcr-content.
I exported the file, renamed it back to jcr:content. After the reimport, the file was shown fine.

PM (Topher) Input

Do a little research why we escape : even though it's allowed character in JCR.

Valid (and actually required) node names are now being renamed to values that cause the system to work incorrectly. The reporter mentions the problem with the "jcr:content" name for assets. (It must be named "jcr:content"). I am not sure if this is the only case for Node names. I can see in linked docu page that there are also some required property names which have a colon, for example "jcr:data" or "jcr:mimeType".

It's challenging to decide on the proper behaviour because on one hand there are node names that require a colon, whereas when users use the UI colons are converted to dashes for the node name.

I propose the following:

Research what other requiired node names include a colon.

Checking if the node name in the REST request includes one of the known "required" names (such as 'jcr:content') and if so dont rename it. A more perissive but probably more future-proof approach would be to check if the node name inclues "jcr:" or "mgnl:" and if so, dont rename it.

The endpoint should return a message if a node has been renamed, and what its new name is. (otherwise the data on the client can get out of sync if it expects a certain name. Imagine the client has a system with 20 products and wants to import those items in Magnoila and maintiain "links" to them based on their names.)

The documentation should be updated to inform what are valid node names and what type of message is returned when invalid ones are supplied.

 

 

Activity

Show:

Milan Divilek February 18, 2022 at 8:28 AM
Edited

Colons is invalid character in JCR Local Names.

InvalidChar ::= '/' | ':' | '[' | ']' | '|' | '*'

JCR name is composed of JCR namespace and JCR local name and colon is used as delimiter.

see https://developer.adobe.com/experience-manager/reference-materials/spec/jcr/2.0/3_Repository_Model.html

Solution:
Correct solution in my opinion is adjust NodeNameHelper to work correctly when name contains also the jcr namespace.

Fixed

Details

Assignee

Reporter

Priority

Fix versions

Story Points

Sprint

More fields

Created February 4, 2022 at 7:37 AM
Updated July 20, 2024 at 1:18 AM
Resolved March 1, 2022 at 6:50 AM