diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2022-04-01 09:18:14 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2022-04-01 09:18:14 +0200 |
commit | a35d53cf3423b2d27df3709c589e849fd126a074 (patch) | |
tree | 7fa2a634466ca4f32f18509916d7209310eec3dc | |
parent | eb0a6f731ed02d5030cb144117393482d1dac296 (diff) |
Even more Path!
7 files changed, 32 insertions, 20 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java index 245288c283e..e134b8f53ac 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java @@ -34,11 +34,6 @@ public class DistributableResource { this.path = path; this.pathType = type; } - public DistributableResource(String name, ByteBuffer blob) { - this.name = name; - path = name + ".lz4"; - pathType = PathType.BLOB; - } //TODO Remove and make path/pathType final public void setFileName(String fileName) { diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankExpressionBody.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankExpressionBody.java index 815e4bbf359..6ba17123fb4 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankExpressionBody.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankExpressionBody.java @@ -6,16 +6,19 @@ import com.yahoo.config.application.api.FileRegistry; import java.nio.ByteBuffer; import java.util.Objects; +import static java.util.Objects.requireNonNull; + public class RankExpressionBody extends DistributableResource { private final ByteBuffer blob; public RankExpressionBody(String name, ByteBuffer blob) { - super(name, blob); - Objects.requireNonNull(blob, "Blob cannot be null"); - this.blob = blob; + super(name, name + ".lz4", PathType.BLOB); + this.blob = requireNonNull(blob, "Blob cannot be null"); } + public ByteBuffer getBlob() { return blob; } + public void validate() { // Remove once pathType is final if (getPathType() != PathType.BLOB) { @@ -26,4 +29,5 @@ public class RankExpressionBody extends DistributableResource { void register(FileRegistry fileRegistry) { register(fileRegistry, blob); } + } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index e7b7c92ca2f..0f2c1cf9a15 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -5,6 +5,7 @@ import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; import com.google.common.collect.ImmutableMap; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.path.Path; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileType; @@ -882,10 +883,10 @@ public class RankProfile implements Cloneable { if (!expression.startsWith("file:")) return new StringReader(expression); String fileName = extractFileName(expression); - File file = new File(fileName); - if (!file.isAbsolute() && file.getPath().contains("/")) // See ticket 4102122 - throw new IllegalArgumentException("In " + name() + ", " + expName + ", ranking references file '" + file + - "' in subdirectory, which is not supported."); + Path.fromString(fileName); // No ".." + if (fileName.contains("/")) // See ticket 4102122 + throw new IllegalArgumentException("In " + name() + ", " + expName + ", ranking references file '" + + fileName + "' in a different directory, which is not supported."); return schema.getRankingExpression(fileName); } diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index 8a4798d6f74..6119eb5e2ce 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -1773,7 +1773,7 @@ String fileItem() : String path; } { - (<FILE> <COLON> ( <FILE_PATH> | <STRING> | <IDENTIFIER>) { path = token.image; } { } (<NL>)*) { return path; } + (<FILE> <COLON> ( <FILE_PATH> | <STRING> | <IDENTIFIER>) { path = com.yahoo.path.Path.fromString(token.image).getRelative(); } { } (<NL>)*) { return path; } } String uriItem() : { diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index aeffe6e5c39..c4542c36779 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -1907,7 +1907,7 @@ String fileItem() : String path; } { - (<FILE> <COLON> ( <FILE_PATH> | <STRING> | <IDENTIFIER>) { path = token.image; } { } (<NL>)*) { return path; } + (<FILE> <COLON> ( <FILE_PATH> | <STRING> | <IDENTIFIER>) { path = com.yahoo.path.Path.fromString(token.image).getRelative(); } { } (<NL>)*) { return path; } } String uriItem() : { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java index 36a72381156..c686a813c9f 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java @@ -62,16 +62,27 @@ public class IntermediateParserTestCase { @Test public void multiple_documents_disallowed() throws Exception { String input = joinLines - ("schema foo {", - " document foo {", - " }", - " document foo2 {", - " }", - "}"); + ("schema foo {", + " document foo {", + " }", + " document foo2 {", + " }", + "}"); var e = assertThrows(IllegalArgumentException.class, () -> parseString(input)); assertEquals("schema 'foo' error: already has document 'foo' so cannot add document 'foo2'", e.getMessage()); } + @Test + public void backwards_path_is_disallowed() { + assertThrows("'..' is not allowed in path", IllegalArgumentException.class, + () -> parseString("schema foo {\n" + + " constant my_constant_tensor {\n" + + " file: foo/../bar\n" + + " type: tensor<float>(x{},y{})\n" + + " }\n" + + "}\n")); + } + void checkFileParses(String fileName) throws Exception { System.err.println("TRY parsing: "+fileName); var schema = parseFile(fileName); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistryTestCase.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistryTestCase.java index 60f42321631..6d7074aef3c 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistryTestCase.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistryTestCase.java @@ -78,4 +78,5 @@ public class FileDBRegistryTestCase { void checkConsistentEntry(FileRegistry.Entry entry, FileRegistry registry) { assertEquals(entry.reference, registry.addFile(entry.relativePath)); } + } |