Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit aa65bba

Browse files
maquinas07jpbelang
authored andcommitted
Fixes cyclic includes causing parser to hang (#589)
* Changing path utils to use normalized paths * Modifying test expected output since paths are now normalized
1 parent 9d47e1b commit aa65bba

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

raml-parser-2/src/main/java/org/raml/v2/internal/utils/ResourcePathUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.raml.v2.internal.utils;
1717

1818
import java.io.File;
19+
import java.net.URI;
1920
import java.util.ArrayList;
2021
import java.util.List;
2122
import java.util.regex.Matcher;
@@ -47,6 +48,16 @@ public static String toAbsoluteLocation(String basePath, String relativePath)
4748
if (lastSlash != -1)
4849
{
4950
result = basePath.substring(0, lastSlash + 1) + relativePath;
51+
if (isUri(result))
52+
{
53+
URI resultUri = URI.create(result);
54+
result = resultUri.normalize().toString();
55+
}
56+
else
57+
{
58+
File resultFile = new File(result);
59+
result = resultFile.toPath().normalize().toString();
60+
}
5061
}
5162
}
5263
if (result.contains("#"))
@@ -56,6 +67,11 @@ public static String toAbsoluteLocation(String basePath, String relativePath)
5667
return result;
5768
}
5869

70+
public static boolean isUri(String includePath)
71+
{
72+
return includePath.startsWith("http:") || includePath.startsWith("https:") || includePath.startsWith("file:");
73+
}
74+
5975
public static boolean isAbsolute(String includePath)
6076
{
6177
return includePath.startsWith("http:") || includePath.startsWith("https:") || includePath.startsWith("file:") || includePath.startsWith("/") || new File(includePath).isAbsolute();

raml-parser-2/src/test/resources/org/raml/v2/parser/include/include-parent/output.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ RamlDocumentNode (Start: 11 , End: 147, On: input.raml, Source: SYObjectNode)
2929
KeyValueNodeImpl (Start: 97 , End: 142, On: libraries/traits/responses/400-fault.raml)
3030
SYStringNode: "type" (Start: 97 , End: 101, On: libraries/traits/responses/400-fault.raml)
3131
TypeDeclarationNodeFragment (Start: 103 , End: 142, On: libraries/traits/responses/400-fault.raml, Source: DefaultRamlTypedFragment)
32-
KeyValueNodeImpl (Start: 20 , End: 32, On: libraries/traits/responses/../../types/platformfault.raml)
33-
SYStringNode: "type" (Start: 20 , End: 24, On: libraries/traits/responses/../../types/platformfault.raml)
34-
NativeTypeExpressionNode: "object" (Start: 26 , End: 32, On: libraries/traits/responses/../../types/platformfault.raml, Source: SYStringNode)
35-
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
36-
SYStringNode: "displayName" (Start: 33 , End: 44, On: libraries/traits/responses/../../types/platformfault.raml)
37-
OverlayableObjectNodeImpl (Start: 46 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml, Source: SYStringNode)
38-
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
32+
KeyValueNodeImpl (Start: 20 , End: 32, On: libraries/types/platformfault.raml)
33+
SYStringNode: "type" (Start: 20 , End: 24, On: libraries/types/platformfault.raml)
34+
NativeTypeExpressionNode: "object" (Start: 26 , End: 32, On: libraries/types/platformfault.raml, Source: SYStringNode)
35+
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/types/platformfault.raml)
36+
SYStringNode: "displayName" (Start: 33 , End: 44, On: libraries/types/platformfault.raml)
37+
OverlayableObjectNodeImpl (Start: 46 , End: 69, On: libraries/types/platformfault.raml, Source: SYStringNode)
38+
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/types/platformfault.raml)
3939
StringNodeImpl: "value" (Start: -1 , End: -1)
40-
OverlayableStringNode: "Platform Fault Datatype" (Start: 46 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
41-
FacetNode (Start: 70 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: KeyValueNodeImpl)
42-
SYStringNode: "properties" (Start: 70 , End: 80, On: libraries/traits/responses/../../types/platformfault.raml)
43-
SYObjectNode (Start: 84 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml)
44-
PropertyNode (Start: 84 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: KeyValueNodeImpl)
45-
SYStringNode: "message" (Start: 84 , End: 91, On: libraries/traits/responses/../../types/platformfault.raml)
46-
TypeDeclarationNode (Start: 93 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: NativeTypeExpressionNode)
40+
OverlayableStringNode: "Platform Fault Datatype" (Start: 46 , End: 69, On: libraries/types/platformfault.raml)
41+
FacetNode (Start: 70 , End: 99, On: libraries/types/platformfault.raml, Source: KeyValueNodeImpl)
42+
SYStringNode: "properties" (Start: 70 , End: 80, On: libraries/types/platformfault.raml)
43+
SYObjectNode (Start: 84 , End: 99, On: libraries/types/platformfault.raml)
44+
PropertyNode (Start: 84 , End: 99, On: libraries/types/platformfault.raml, Source: KeyValueNodeImpl)
45+
SYStringNode: "message" (Start: 84 , End: 91, On: libraries/types/platformfault.raml)
46+
TypeDeclarationNode (Start: 93 , End: 99, On: libraries/types/platformfault.raml, Source: NativeTypeExpressionNode)
4747
KeyValueNodeImpl (Start: -1 , End: 99)
4848
StringNodeImpl: "type" (Start: -1 , End: -1)
49-
NativeTypeExpressionNode: "string" (Start: 93 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: NativeTypeExpressionNode)
49+
NativeTypeExpressionNode: "string" (Start: 93 , End: 99, On: libraries/types/platformfault.raml, Source: NativeTypeExpressionNode)
5050
KeyValueNodeImpl (Start: -1 , End: -1)
5151
StringNodeImpl: "displayName" (Start: -1 , End: -1)
5252
ObjectNodeImpl (Start: -1 , End: -1)

0 commit comments

Comments
 (0)