@@ -83,9 +83,10 @@ public SolidContainer(final URI identifier, final Dataset dataset, final Metadat
8383 */
8484 public Set <SolidResource > getResources () {
8585 // As defined by the Solid Protocol, containers always end with a slash.
86- if (getIdentifier ().getPath ().endsWith ("/" )) {
87- final String container = normalize (getIdentifier ());
88- final Node node = new Node (rdf .createIRI (getIdentifier ().toString ()), getGraph ());
86+ final URI base = getIdentifier ().normalize ();
87+ if (isContainer (base )) {
88+ final String container = normalize (base );
89+ final Node node = new Node (rdf .createIRI (base .toString ()), getGraph ());
8990 try (final Stream <Node .TypedNode > stream = node .getResources ()) {
9091 return stream .filter (child -> verifyContainmentIri (container , child )).map (child -> {
9192 final Metadata .Builder builder = Metadata .newBuilder ();
@@ -102,12 +103,13 @@ public Set<SolidResource> getResources() {
102103 public ValidationResult validate () {
103104 final List <String > messages = new ArrayList <>();
104105 // Verify that the container URI path ends with a slash
105- if (!getIdentifier ().getPath ().endsWith ("/" )) {
106+ final URI base = getIdentifier ().normalize ();
107+ if (!isContainer (base )) {
106108 messages .add ("Container URI does not end in a slash" );
107109 }
108110
109111 // Get the normalized container URI
110- final String container = normalize (getIdentifier () );
112+ final String container = normalize (base );
111113 // Verify that all ldp:contains triples align with Solid expectations
112114 getGraph ().stream (null , rdf .createIRI (LDP .contains .toString ()), null )
113115 .collect (Collectors .partitioningBy (verifyContainmentTriple (container )))
@@ -121,6 +123,10 @@ public ValidationResult validate() {
121123 return new ValidationResult (false , messages );
122124 }
123125
126+ static boolean isContainer (final URI uri ) {
127+ return uri .normalize ().getPath ().endsWith ("/" );
128+ }
129+
124130 static String normalize (final URI uri ) {
125131 return uri .normalize ().toString ().split ("#" )[0 ].split ("\\ ?" )[0 ];
126132 }
@@ -142,29 +148,30 @@ static Predicate<Triple> verifyContainmentTriple(final String container) {
142148
143149 static boolean verifyContainmentIri (final String container , final IRI object ) {
144150
145- // 1 URI Structure Tests
151+ // URI Structure Tests
152+ final URI base = URI .create (container ).normalize ();
146153 final URI normalized = URI .create (object .getIRIString ()).normalize ();
147154
148- // 1.A Query strings are not allowed in object URI
149- if (normalized .getQuery () != null ) {
155+ // Query strings are not allowed in subject or object URI
156+ if (base . getQuery () != null || normalized .getQuery () != null ) {
150157 return false ;
151158 }
152159
153- // 1.B URI fragments are not allowed in object URI
154- if (normalized .getFragment () != null ) {
160+ // URI fragments are not allowed in subject or object URI
161+ if (base . getFragment () != null || normalized .getFragment () != null ) {
155162 return false ;
156163 }
157164
158- // 2 Relative path tests
159- final URI base = URI .create (container ).normalize ();
160- final URI relative = base .relativize (normalized );
161-
162- // 2.A Base URI cannot equal the object URI
163- if (base .equals (normalized )) {
165+ // Base URI cannot equal the object URI
166+ if (base .getScheme ().equals (normalized .getScheme ()) &&
167+ base .getSchemeSpecificPart ().equals (normalized .getSchemeSpecificPart ())) {
164168 return false ;
165169 }
166170
167- // 2.B Object URI must be relative to (contained in) the base URI
171+ // Relative path tests
172+ final URI relative = base .relativize (normalized );
173+
174+ // Object URI must be relative to (contained in) the base URI
168175 if (relative .isAbsolute ()) {
169176 return false ;
170177 }
@@ -173,7 +180,7 @@ static boolean verifyContainmentIri(final String container, final IRI object) {
173180 final String normalizedPath = relativePath .endsWith ("/" ) ?
174181 relativePath .substring (0 , relativePath .length () - 1 ) : relativePath ;
175182
176- // 2.C Containment cannot skip intermediate nodes
183+ // Containment cannot skip intermediate nodes
177184 if (normalizedPath .contains ("/" )) {
178185 return false ;
179186 }
0 commit comments