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

Commit

Permalink
Fix for #661, using File.separatorChar (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbelang authored Oct 13, 2019
1 parent 296aa97 commit 4c59d94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/main/java/org/raml/parser/tagresolver/ContextPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.raml.parser.tagresolver.IncludeResolver.INCLUDE_APPLIED_TAG;

import java.io.File;
import java.util.ArrayDeque;
import java.util.Deque;

Expand Down Expand Up @@ -70,7 +71,7 @@ public static String resolveAbsolutePath(String relativeFile, String parentPath)

public String resolveAbsolutePath(String relativeFile)
{
return resolveAbsolutePath(relativeFile, getPartentPath());
return resolveAbsolutePath(relativeFile, getParentPath());
}

/**
Expand All @@ -91,25 +92,25 @@ public String resolveRelativePath(Tag tag)
{
throw new IllegalArgumentException("Tag must be an include applied");
}
String partentPath = getPartentPath();
String parentPath = getParentPath();
String includePath = new IncludeInfo(tag).getIncludeName();

if (includePath.startsWith(partentPath))
if (includePath.startsWith(parentPath))
{
includePath = includePath.substring(partentPath.length());
includePath = includePath.substring(parentPath.length());
}
return includePath;
}

public static String getPartentPath(String path)
public static String getParentPath(String path)
{
int idx = path.lastIndexOf("/") + 1;
int idx = path.lastIndexOf(File.separatorChar) + 1;
return path.substring(0, idx);
}

private String getPartentPath()
private String getParentPath()
{
return getPartentPath(includeStack.peek().getIncludeName());
return getParentPath(includeStack.peek().getIncludeName());
}

public IncludeInfo peek()
Expand All @@ -129,7 +130,7 @@ public void push(IncludeInfo includeInfo)

public void push(ScalarNode node)
{
push(new IncludeInfo(node, getPartentPath()));
push(new IncludeInfo(node, getParentPath()));
}

public void push(Tag tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private Node resolveInclude(Node node, Tag tag)
// parent include applied tag path
ScalarNode scalarNode = (ScalarNode) node;
String parentPath = includeResolver.getContextPath().resolveRelativePath(tag);
String includePathRecalculated = ContextPath.getPartentPath(parentPath) + scalarNode.getValue();
String includePathRecalculated = ContextPath.getParentPath(parentPath) + scalarNode.getValue();
node = new ScalarNode(scalarNode.getTag(), includePathRecalculated, node.getStartMark(), node.getEndMark(), scalarNode.getStyle());
}
return includeResolver.resolve(node, resourceLoader, nodeNandler);
Expand Down

0 comments on commit 4c59d94

Please sign in to comment.