diff options
13 files changed, 91 insertions, 90 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java index 640e5156615..5ec30f71e7b 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java @@ -619,7 +619,6 @@ public class FilesApplicationPackage implements ApplicationPackage { @Override public Reader getRankingExpression(String name) { try { - File file = expressionFileNameToFile(name); return IOUtils.createReader(expressionFileNameToFile(name), "utf-8"); } catch (IOException e) { diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index 66fa308f32f..e50cbabeb9f 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -360,8 +360,7 @@ TOKEN : | < CONSTANTS: "constants" > | < FILE: "file" > | < URI: "uri" > -| < IDENTIFIER: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_"])* > -| < IDENTIFIER_WITH_DASH: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-"])* > +| < IDENTIFIER: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-"])* > | < QUOTEDSTRING: "\"" ( ~["\""] )* "\"" > | < CONTEXT: ["a"-"z","A"-"Z"] (["a"-"z", "A"-"Z", "0"-"9"])* > | < DOUBLE: ("-")? (["0"-"9"])+ "." (["0"-"9"])+ > @@ -419,7 +418,10 @@ Search rootSearch(String dir) : Search search; } { - ( <SEARCH> name = identifier() { search = new Search(name, app); + ( <SEARCH> name = identifier() { if (!name.matches("[a-zA-Z_][a-zA-Z_:0-9]*")) { + deployLogger.log(Level.WARNING, name + " can not be used in YQL+ expressions."); + } + search = new Search(name, app); rankProfileRegistry.add(new DefaultRankProfile(search, rankProfileRegistry)); rankProfileRegistry.add(new UnrankedRankProfile(search, rankProfileRegistry));} lbrace() (rootSearchItem(search) (<NL>)*)* <RBRACE> (<NL>)* <EOF>) @@ -670,15 +672,14 @@ void fieldSetItem(String setName, Search search) : ( <FIELDS><COLON> field=identifier() { search.fieldSets().addUserFieldSetItem(setName, field); } ( <COMMA> field=identifier() { search.fieldSets().addUserFieldSetItem(setName, field); } )* ) | - ( <QUERYCOMMAND> <COLON> (queryCommand = identifierWithDash() | queryCommand = quotedString())) { search.fieldSets().userFieldSets().get(setName).queryCommands().add(queryCommand);} + ( <QUERYCOMMAND> <COLON> (queryCommand = identifier() | queryCommand = quotedString())) { search.fieldSets().userFieldSets().get(setName).queryCommands().add(queryCommand);} | ( match(matchSettings) ) { matchSettings.applyOperations(); search.fieldSets().userFieldSets().get(setName).setMatching(matchSettings.getMatching());} } /** * This rule consumes a annotation block from within either a document element or a search element. - - * @param search the search object to add content to. + * @param search The search object to add content to. */ void annotationOutside(Search search) : { @@ -700,7 +701,6 @@ void annotationOutside(Search search) : /** * This rule consumes a annotation block from within either a document element. - * * @param document The document object to add content to. */ void annotation(Search search, SDDocumentType document) : @@ -1186,7 +1186,7 @@ Object sortingSetting(SortingOperation sorting, String attributeName) : | <QUATERNARY> { sorting.setStrength(Sorting.Strength.QUATERNARY); } | <IDENTICAL> { sorting.setStrength(Sorting.Strength.IDENTICAL); } ) - | <LOCALE> <COLON> locale = identifierWithDash() { sorting.setLocale(locale); } + | <LOCALE> <COLON> locale = identifier() { sorting.setLocale(locale); } ) { return null; } } @@ -1438,7 +1438,7 @@ void summaryProperty(SummaryInFieldLongOperation field) : String name, value; } { - name = identifierWithDash() <COLON> (value = identifierWithDash() | value = quotedString()) + name = identifier() <COLON> (value = identifier() | value = quotedString()) { field.addProperty(new SummaryField.Property(name, value)); } } @@ -1453,7 +1453,7 @@ void fieldStemming(FieldOperationContainer field) : StemmingOperation op = new StemmingOperation(); } { - <STEMMING> <COLON> setting = identifierWithDash() + <STEMMING> <COLON> setting = identifier() { op.setSetting(setting); field.addOperation(op); @@ -1470,7 +1470,7 @@ void searchStemming(Search search) : String setting; } { - <STEMMING> <COLON> setting = identifierWithDash() + <STEMMING> <COLON> setting = identifier() { search.setStemming(Stemming.get(setting)); } } @@ -1485,7 +1485,7 @@ void normalizing(FieldOperationContainer field) : String setting; } { - <NORMALIZING> <COLON> setting = identifierWithDash() + <NORMALIZING> <COLON> setting = identifier() { field.addOperation(new NormalizingOperation(setting)); } @@ -1543,7 +1543,7 @@ void queryCommand(FieldOperationContainer container) : QueryCommandOperation field = new QueryCommandOperation(); } { - <QUERYCOMMAND> <COLON> command = identifierWithDash() + <QUERYCOMMAND> <COLON> command = identifier() { field.addQueryCommand(command); container.addOperation(field); @@ -1556,7 +1556,7 @@ void alias(FieldOperationContainer container) : String alias; } { - <ALIAS> [aliasedName = identifier()] <COLON> alias = identifierWithDash() + <ALIAS> [aliasedName = identifier()] <COLON> alias = identifier() { AliasOperation op = new AliasOperation(aliasedName, alias); container.addOperation(op); @@ -1790,9 +1790,9 @@ Object indexBody(IndexOperation index) : double threshold; } { - ( <PREFIX> { index.setPrefix(true); } - | <ALIAS> <COLON> str = identifierWithDash() { index.addAlias(str); } - | <STEMMING> <COLON> str = identifierWithDash() { index.setStemming(str); } + ( <PREFIX> { index.setPrefix(true); } + | <ALIAS> <COLON> str = identifier() { index.addAlias(str); } + | <STEMMING> <COLON> str = identifier() { index.setStemming(str); } | <RISE> { if (true) throw new ParseException("'index:rise' is no longer an option. Use 'indexing:attribute' instead. " + "If it is a weighted set field you should also add 'attribute:fast-search'." + @@ -1877,7 +1877,7 @@ void rankProfile(Search search) : RankProfile profile; } { - ( <RANKPROFILE> name = identifierWithDash() + ( <RANKPROFILE> name = identifier() { if (documentsOnly) { profile = new DocumentsOnlyRankProfile(name, search, rankProfileRegistry); @@ -1934,7 +1934,7 @@ void inheritsRankProfile(RankProfile profile) : String str; } { - <INHERITS> str = identifierWithDash() + <INHERITS> str = identifier() { profile.setInherited(str); } } @@ -2233,9 +2233,9 @@ String rankPropertyItem() : String image, ret = ""; } { - ( ( image = identifierWithDash() { ret += image; } - | image = quotedString() { ret += image; } - | ( "(" | ")" | <DOT> | <COMMA> ) { ret += token.image; } )+ ) + ( ( image = identifier() { ret += image; } + | image = quotedString() { ret += image; } + | ( "(" | ")" | <DOT> | <COMMA> ) { ret += token.image; } )+ ) { return ret; } } @@ -2476,16 +2476,6 @@ String expression() : { return exp; } } -String identifierWithDash() : -{ - String identifier; -} -{ - ( identifier = identifier() { return identifier; } ) - | - ( <IDENTIFIER_WITH_DASH> { return token.image; } ) -} - /** * This rule consumes an identifier. This must be kept in sync with all word tokens that should be parseable as * identifiers. diff --git a/config-model/src/test/examples/invalid-name.sd b/config-model/src/test/examples/invalid-name.sd deleted file mode 100644 index f26fcc723f4..00000000000 --- a/config-model/src/test/examples/invalid-name.sd +++ /dev/null @@ -1,12 +0,0 @@ -# Dashes in names are not allowed -search invalid-name { - - document invalid-name { - - field title type string { - - } - - } - -}
\ No newline at end of file diff --git a/config-model/src/test/examples/simple-with-weird-name.sd b/config-model/src/test/examples/simple-with-weird-name.sd new file mode 100644 index 00000000000..109f4f7bba7 --- /dev/null +++ b/config-model/src/test/examples/simple-with-weird-name.sd @@ -0,0 +1,13 @@ +# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +# A minimal doc with name which is incompatible with YQL+ +search simple-with-weird-name { + + document simple-with-weird-name { + + field title type string { + indexing: summary | index + } + + } + +} diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java index a26154fc8da..278471cb37a 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java @@ -73,16 +73,35 @@ public class SearchDefinitionsParsingTestCase extends SearchDefinitionTestCase { } } - @Test - public void illegalSearchDefinitionName() throws IOException, ParseException { - try { - SearchBuilder.buildFromFile("src/test/examples/invalid-name.sd"); - fail("Name with dash passed"); - } catch (ParseException e) { - if ( ! e.getMessage().contains("invalid-name")) { - throw e; + private static class WarningCatcher extends Handler { + volatile boolean gotYqlWarning = false; + + @Override + public void publish(LogRecord record) { + if (record.getLevel() == Level.WARNING && record.getMessage().indexOf("YQL") >= 0) { + gotYqlWarning = true; } } + + @Override + public void flush() { + // intentionally left blank + } + + @Override + public void close() throws SecurityException { + // intentionally left blank + } } + + @Test + public void requireYqlCompatibilityIsTested() throws Exception { + Logger log = Logger.getLogger("DeployLogger"); + WarningCatcher w = new WarningCatcher(); + log.addHandler(w); + assertNotNull(SearchBuilder.buildFromFile("src/test/examples/simple-with-weird-name.sd")); + log.removeHandler(w); + assertTrue(w.gotYqlWarning); + } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java index 4180f9f6de4..30f1df6a394 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.*; /** * @author gjoranv + * @since 5.1.10 */ public class SearchBuilderTest extends ContainerModelBuilderTestBase { @@ -34,7 +35,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { } @Test - public void gui_search_handler_is_always_included_when_search_is_specified() { + public void gui_search_handler_is_always_included_when_search_is_specified() throws Exception{ Element clusterElem = DomBuilderTest.parse( "<jdisc id='default' version='1.0'>", " <search />", @@ -60,7 +61,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { @Test - public void search_handler_bindings_can_be_overridden() { + public void search_handler_bindings_can_be_overridden() throws Exception { Element clusterElem = DomBuilderTest.parse( "<jdisc id='default' version='1.0'>", " <search>", @@ -79,7 +80,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { } @Test - public void search_handler_bindings_can_be_disabled() { + public void search_handler_bindings_can_be_disabled() throws Exception { Element clusterElem = DomBuilderTest.parse( "<jdisc id='default' version='1.0'>", " <search>", @@ -110,7 +111,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { assertThat(chainsConfig().chains(), hasItemWithMethod("vespa", "id")); } - private void createClusterWithOnlyDefaultChains() { + private void createClusterWithOnlyDefaultChains() throws SAXException, IOException { Element containerElem = DomBuilderTest.parse( "<jdisc id='default' version='1.0'>", " <search/>", @@ -123,7 +124,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { } @Test - public void manually_setting_up_search_handler_is_forbidden() { + public void manually_setting_up_search_handler_is_forbidden() throws IOException, SAXException { try { Element clusterElem = DomBuilderTest.parse( "<jdisc id='default' version='1.0'>", @@ -192,7 +193,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { } - private VespaModel getVespaModelWithMusic(String hosts, String services) { + private VespaModel getVespaModelWithMusic(String hosts, String services) throws ParseException { return new VespaModelCreatorWithMockPkg(hosts, services, ApplicationPackageUtils.generateSearchDefinitions("music")).create(); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java index 66f59717407..0ad5fb3b0bd 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java @@ -47,7 +47,7 @@ public class ReservedDocumentTypeNameValidatorTest { public void validation_is_case_insensitive() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The following document types conflict with reserved keyword names: " + - "'NULL', 'True', 'anD'."); + "'NULL', 'True', 'anD'."); ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(Arrays.asList("NULL", "True", "anD"))); diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index dae6b9f0fb9..ed80c0bf256 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -308,17 +308,6 @@ public class QueryTestCase { } @Test - public void testLanguageSubstitution() { - QueryProfile profile = new QueryProfile("myProfile"); - profile.set("myField1", "Language: %{model.language}", null); - profile.set("myField2", "Locale: %{locale}", null); - Query q = new Query(QueryTestCase.httpEncode("/search?lang=en-us"), profile.compile(null)); - assertEquals("Language: ENGLISH", q.properties().get("myField1")); - q.properties().set("locale", q.getHttpRequest().propertyMap().get("lang")); - assertEquals("Locale: en-us", q.properties().get("myField2")); - } - - @Test public void testTimeoutInRequestOverridesQueryProfile() { QueryProfile profile = new QueryProfile("test"); profile.set("timeout", 318, (QueryProfileRegistry)null); diff --git a/jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilter.java b/jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilter.java index 3c154fa4d89..5b79b806190 100644 --- a/jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilter.java +++ b/jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilter.java @@ -69,7 +69,7 @@ public class AthenzPrincipalFilter extends CorsRequestFilterBase { if (!certificatePrincipal.isPresent() && !nTokenPrincipal.isPresent()) { String errorMessage = "Unable to authenticate Athenz identity. " + - "Either client certificate or principal token is required."; + "Either client certificate or principal token is required."; return createResponse(request, Response.Status.UNAUTHORIZED, errorMessage); } if (certificatePrincipal.isPresent() && nTokenPrincipal.isPresent() diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/filter/DiscFilterRequest.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/filter/DiscFilterRequest.java index f7ab399574c..da76e288a2a 100644 --- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/filter/DiscFilterRequest.java +++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/filter/DiscFilterRequest.java @@ -67,7 +67,8 @@ public abstract class DiscFilterRequest { public abstract void setUri(URI uri); public HttpRequest getParentRequest() { - throw new UnsupportedOperationException("getParentRequest is not supported for " + parent.getClass().getName()); + throw new UnsupportedOperationException( + "getParentRequest is not supported for " + parent.getClass().getName()); } /** @@ -339,8 +340,8 @@ public abstract class DiscFilterRequest { * is included in the specified logical "role". */ public boolean isUserInRole(String role) { - if (overrideIsUserInRole) { - if (roles != null) { + if(overrideIsUserInRole) { + if(roles != null) { for (String role1 : roles) { if (role1 != null && role1.trim().length() > 0) { String userRole = role1.trim(); @@ -399,7 +400,7 @@ public abstract class DiscFilterRequest { */ public void setCharacterEncoding(String encoding) { String charEncoding = setCharsetFromContentType(this.getContentType(), encoding); - if (charEncoding != null && !charEncoding.isEmpty()) { + if(charEncoding != null && !charEncoding.isEmpty()) { removeHeaders(HttpHeaders.Names.CONTENT_TYPE); setHeaders(HttpHeaders.Names.CONTENT_TYPE, charEncoding); } @@ -409,11 +410,11 @@ public abstract class DiscFilterRequest { * Can be called multiple times to add Cookies */ public void addCookie(JDiscCookieWrapper cookie) { - if (cookie != null) { - List<Cookie> cookies = new ArrayList<>(); - // Get current set of cookies first + if(cookie != null) { + List<Cookie> cookies = new ArrayList<Cookie>(); + //Get current set of cookies first List<Cookie> c = getCookies(); - if (c != null && !c.isEmpty()) { + if(c != null && !c.isEmpty()) { cookies.addAll(c); } cookies.add(cookie.getCookie()); @@ -425,7 +426,7 @@ public abstract class DiscFilterRequest { public JDiscCookieWrapper[] getWrappedCookies() { List<Cookie> cookies = getCookies(); - if (cookies == null) { + if(cookies == null) { return null; } List<JDiscCookieWrapper> cookieWrapper = new ArrayList<>(cookies.size()); @@ -507,9 +508,12 @@ public abstract class DiscFilterRequest { } protected static ThreadLocalSimpleDateFormat formats[] = { - new ThreadLocalSimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), - new ThreadLocalSimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), - new ThreadLocalSimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US) }; + new ThreadLocalSimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", + Locale.US), + new ThreadLocalSimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", + Locale.US), + new ThreadLocalSimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", + Locale.US) }; /** * The set of SimpleDateFormat formats to use in getDateHeader(). @@ -517,8 +521,8 @@ public abstract class DiscFilterRequest { * Notice that because SimpleDateFormat is not thread-safe, we can't declare * formats[] as a static variable. */ - protected static final class ThreadLocalSimpleDateFormat extends ThreadLocal<SimpleDateFormat> { - + protected static final class ThreadLocalSimpleDateFormat extends + ThreadLocal<SimpleDateFormat> { private final String format; private final Locale locale; @@ -537,7 +541,6 @@ public abstract class DiscFilterRequest { public Date parse(String value) throws ParseException { return get().parse(value); } - } } diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/servlet/ServletRequest.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/servlet/ServletRequest.java index 2eb7f432ec2..e6bb99d4647 100644 --- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/servlet/ServletRequest.java +++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/servlet/ServletRequest.java @@ -33,9 +33,10 @@ import static com.yahoo.jdisc.http.core.HttpServletRequestUtils.getConnection; * You might find it tempting to remove e.g. the getParameter... methods, * but keep in mind that this IS-A servlet request and must provide the * full api of such a request for use outside the "JDisc filter world". + * + * @since 5.27 */ public class ServletRequest extends HttpServletRequestWrapper implements ServletOrJdiscHttpRequest { - public static final String JDISC_REQUEST_PRINCIPAL = "jdisc.request.principal"; public static final String JDISC_REQUEST_X509CERT = "jdisc.request.X509Certificate"; public static final String SERVLET_REQUEST_X509CERT = "javax.servlet.request.X509Certificate"; diff --git a/security-utils/src/main/java/com/yahoo/security/KeyUtils.java b/security-utils/src/main/java/com/yahoo/security/KeyUtils.java index 491178f8801..0d45a62f193 100644 --- a/security-utils/src/main/java/com/yahoo/security/KeyUtils.java +++ b/security-utils/src/main/java/com/yahoo/security/KeyUtils.java @@ -38,7 +38,6 @@ import static com.yahoo.security.KeyAlgorithm.RSA; * @author bjorncs */ public class KeyUtils { - private KeyUtils() {} public static KeyPair generateKeypair(KeyAlgorithm algorithm, int keySize) { diff --git a/security-utils/src/main/java/com/yahoo/security/X509CertificateUtils.java b/security-utils/src/main/java/com/yahoo/security/X509CertificateUtils.java index fc7a6780b23..33bd750bac5 100644 --- a/security-utils/src/main/java/com/yahoo/security/X509CertificateUtils.java +++ b/security-utils/src/main/java/com/yahoo/security/X509CertificateUtils.java @@ -133,5 +133,4 @@ public class X509CertificateUtils { throw new UncheckedIOException(e); } } - } |