[
https://issues.apache.org/jira/browse/TINKERPOP-2683?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17470692#comment-17470692
]
Fredrick Eisele edited comment on TINKERPOP-2683 at 1/7/22, 3:58 PM:
---------------------------------------------------------------------
The grammar seems to assume the Groovy grammar as a starting point.
Groovy allows the escaped backslash in strings.
There is a third (and probably correct) alternative.
The path could be escaped before being inserted into the script.
[escapeJava|http://docs.groovy-lang.org/latest/html/gapi/groovy/json/StringEscapeUtils.html#escapeJava(java.lang.String)]
I have not tested the following but I think it shows the approach.
{code:java}
private String tryUpdateDataFilePath(final String docString) {
final Matcher matcher = ioPattern.matcher(docString);
if (matcher.matches()) { return docString; }
final String relPath = matcher.group(1);
final String absPath = world.changePathToDataFile(relPath);
final String gremlin = docString.replace(relPath, escapeJava(absPath));
return gremlin;
}
{code}
was (Author: phreed):
The grammar seems to assume the Groovy grammar as a starting point.
Groovy allows the escaped backslash in strings.
There is a third (and probably correct) alternative.
The path could be escaped before being inserted into the script.
[escapeJava|http://docs.groovy-lang.org/latest/html/gapi/groovy/json/StringEscapeUtils.html#escapeJava(java.lang.String)]
I have not tested the following but I think it shows the approach.
{code:java}
private String tryUpdateDataFilePath(final String docString) {
final Matcher matcher = ioPattern.matcher(docString);
if (matcher.matches()) { return docString; }
final String relPath = matcher.group(1);
final String absPath = world.changePathToDataFile(relPath);
final String gremlin = docString.replace(relpath, escapeJava(absPath));
return gremlin;
}
{code}
> Defective Path in Testing g.io()
> --------------------------------
>
> Key: TINKERPOP-2683
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2683
> Project: TinkerPop
> Issue Type: Bug
> Components: tinkergraph
> Affects Versions: 3.5.1
> Reporter: Fredrick Eisele
> Priority: Blocker
> Labels: easyfix, test-stability
>
> I found a small bug in the tinkergraph testing on windows 10.
> It comes up because the grammar does not allow a '\' ...
> {code:none}
> fragment
> DoubleQuotedStringCharacters
> : DoubleQuotedStringCharacter+
> ;
> fragment
> DoubleQuotedStringCharacter
> : ~('"' | '\\')
> | JoinLineEscape
> | EscapeSequence
> ;
> {code}
> ```
> ...and the function which locates the g.io() file adds in a '\'.
> [TinkerGraphWorld.java|https://github.com/apache/tinkerpop/blob/53503bfa28ba1de061204fb96835dee856576bbf/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphWorld.java]
> {code:java}
> @Override
> public String changePathToDataFile(final String pathToFileFromGremlin) {
> return ".." + File.separator + pathToFileFromGremlin;
> }
> {code}
> The File.separator on linux is a valid character '/' but the problematic '\'
> character on Windows 10.
> Which gets called by...
> [StepDefinition.java|https://github.com/apache/tinkerpop/blob/53503bfa28ba1de061204fb96835dee856576bbf/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java]
> {code:java}
> private String tryUpdateDataFilePath(final String docString) {
> final Matcher matcher = ioPattern.matcher(docString);
> final String gremlin = matcher.matches() ?
> docString.replace(matcher.group(1),
> world.changePathToDataFile(matcher.group(1))) : docString;
> return gremlin;
> }
> {code}
> In particular this gets triggered by the
> [Read.feature|https://github.com/apache/tinkerpop/blob/53503bfa28ba1de061204fb96835dee856576bbf/gremlin-test/features/sideEffect/Read.feature]
> .
--
This message was sent by Atlassian Jira
(v8.20.1#820001)