From 6b189b318a5f93ca553ade95109bc5afa4dfb681 Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Fri, 27 Apr 2018 10:03:31 +0200 Subject: [PATCH] issue 3804 fix (SelectableEntityFiltering when the fields specified is . character) Signed-off-by: Maxim Nesen --- .../selectable/PersonResourceTest.java | 22 +++++++++++++++++++ .../filtering/SelectableScopeResolver.java | 3 +++ 2 files changed, 25 insertions(+) diff --git a/examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java b/examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java index dc0a2757a1..3dc9acede6 100644 --- a/examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java +++ b/examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java @@ -136,6 +136,28 @@ public void testFilters() throws Exception { assertThat(entity.getRegion(), nullValue()); } + /** + * Test empty (but valid) filters. + * Valid empty filters are: + * . ,. , .. ., + * + * + * result is empty object (nothing is returned) but Jersey will not throw any exception + */ + @Test + public void testEmptyFilters() throws Exception { + final Person entity = target("people").path("1234") + .queryParam("select", ".").request() + .get(Person.class); + + // Null values (all elements). + assertThat(entity.getFamilyName(), nullValue()); + assertThat(entity.getGivenName(), nullValue()); + assertThat(entity.getAddresses(), nullValue()); + assertThat(entity.getPhoneNumbers(), nullValue()); + assertThat(entity.getRegion(), nullValue()); + } + /** * Test 2nd and 3rd level filters. */ diff --git a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/SelectableScopeResolver.java b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/SelectableScopeResolver.java index 6e22afbee1..ff0437b06b 100644 --- a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/SelectableScopeResolver.java +++ b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/SelectableScopeResolver.java @@ -83,6 +83,9 @@ private Set getScopesForField(final String fieldName) { final String[] fields = Tokenizer.tokenize(fieldName, ","); for (final String field : fields) { final String[] subfields = Tokenizer.tokenize(field, "."); + if (subfields.length == 0) { + continue; + } // in case of nested path, add first level as stand-alone to ensure subgraph is added scopes.add(SelectableScopeResolver.PREFIX + subfields[0]); if (subfields.length > 1) {