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

Commit

Permalink
Fixes cyclic includes causing parser to hang (#589)
Browse files Browse the repository at this point in the history
* Changing path utils to use normalized paths

* Modifying test expected output since paths are now normalized
  • Loading branch information
maquinas07 authored and jpbelang committed Mar 14, 2019
1 parent 9d47e1b commit aa65bba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.raml.v2.internal.utils;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -47,6 +48,16 @@ public static String toAbsoluteLocation(String basePath, String relativePath)
if (lastSlash != -1)
{
result = basePath.substring(0, lastSlash + 1) + relativePath;
if (isUri(result))
{
URI resultUri = URI.create(result);
result = resultUri.normalize().toString();
}
else
{
File resultFile = new File(result);
result = resultFile.toPath().normalize().toString();
}
}
}
if (result.contains("#"))
Expand All @@ -56,6 +67,11 @@ public static String toAbsoluteLocation(String basePath, String relativePath)
return result;
}

public static boolean isUri(String includePath)
{
return includePath.startsWith("http:") || includePath.startsWith("https:") || includePath.startsWith("file:");
}

public static boolean isAbsolute(String includePath)
{
return includePath.startsWith("http:") || includePath.startsWith("https:") || includePath.startsWith("file:") || includePath.startsWith("/") || new File(includePath).isAbsolute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ RamlDocumentNode (Start: 11 , End: 147, On: input.raml, Source: SYObjectNode)
KeyValueNodeImpl (Start: 97 , End: 142, On: libraries/traits/responses/400-fault.raml)
SYStringNode: "type" (Start: 97 , End: 101, On: libraries/traits/responses/400-fault.raml)
TypeDeclarationNodeFragment (Start: 103 , End: 142, On: libraries/traits/responses/400-fault.raml, Source: DefaultRamlTypedFragment)
KeyValueNodeImpl (Start: 20 , End: 32, On: libraries/traits/responses/../../types/platformfault.raml)
SYStringNode: "type" (Start: 20 , End: 24, On: libraries/traits/responses/../../types/platformfault.raml)
NativeTypeExpressionNode: "object" (Start: 26 , End: 32, On: libraries/traits/responses/../../types/platformfault.raml, Source: SYStringNode)
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
SYStringNode: "displayName" (Start: 33 , End: 44, On: libraries/traits/responses/../../types/platformfault.raml)
OverlayableObjectNodeImpl (Start: 46 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml, Source: SYStringNode)
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
KeyValueNodeImpl (Start: 20 , End: 32, On: libraries/types/platformfault.raml)
SYStringNode: "type" (Start: 20 , End: 24, On: libraries/types/platformfault.raml)
NativeTypeExpressionNode: "object" (Start: 26 , End: 32, On: libraries/types/platformfault.raml, Source: SYStringNode)
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/types/platformfault.raml)
SYStringNode: "displayName" (Start: 33 , End: 44, On: libraries/types/platformfault.raml)
OverlayableObjectNodeImpl (Start: 46 , End: 69, On: libraries/types/platformfault.raml, Source: SYStringNode)
KeyValueNodeImpl (Start: 33 , End: 69, On: libraries/types/platformfault.raml)
StringNodeImpl: "value" (Start: -1 , End: -1)
OverlayableStringNode: "Platform Fault Datatype" (Start: 46 , End: 69, On: libraries/traits/responses/../../types/platformfault.raml)
FacetNode (Start: 70 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: KeyValueNodeImpl)
SYStringNode: "properties" (Start: 70 , End: 80, On: libraries/traits/responses/../../types/platformfault.raml)
SYObjectNode (Start: 84 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml)
PropertyNode (Start: 84 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: KeyValueNodeImpl)
SYStringNode: "message" (Start: 84 , End: 91, On: libraries/traits/responses/../../types/platformfault.raml)
TypeDeclarationNode (Start: 93 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: NativeTypeExpressionNode)
OverlayableStringNode: "Platform Fault Datatype" (Start: 46 , End: 69, On: libraries/types/platformfault.raml)
FacetNode (Start: 70 , End: 99, On: libraries/types/platformfault.raml, Source: KeyValueNodeImpl)
SYStringNode: "properties" (Start: 70 , End: 80, On: libraries/types/platformfault.raml)
SYObjectNode (Start: 84 , End: 99, On: libraries/types/platformfault.raml)
PropertyNode (Start: 84 , End: 99, On: libraries/types/platformfault.raml, Source: KeyValueNodeImpl)
SYStringNode: "message" (Start: 84 , End: 91, On: libraries/types/platformfault.raml)
TypeDeclarationNode (Start: 93 , End: 99, On: libraries/types/platformfault.raml, Source: NativeTypeExpressionNode)
KeyValueNodeImpl (Start: -1 , End: 99)
StringNodeImpl: "type" (Start: -1 , End: -1)
NativeTypeExpressionNode: "string" (Start: 93 , End: 99, On: libraries/traits/responses/../../types/platformfault.raml, Source: NativeTypeExpressionNode)
NativeTypeExpressionNode: "string" (Start: 93 , End: 99, On: libraries/types/platformfault.raml, Source: NativeTypeExpressionNode)
KeyValueNodeImpl (Start: -1 , End: -1)
StringNodeImpl: "displayName" (Start: -1 , End: -1)
ObjectNodeImpl (Start: -1 , End: -1)
Expand Down

0 comments on commit aa65bba

Please sign in to comment.