forked from geoserver/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-11720] AttributeTypeInfoImpl doesn't quote names properly
At least two issues found here: 1. Simply being able to parse a string as ECQL doesn't tell us if the resulting ECQL would do what we want - what we need to know, before deciding to apply quotes, is if the ECQL parser would currently parse this field name as a PropertyName (what we want) or something else. 2. Not all ECQL parsing failures are CQLException - there is also EmptyStackException and there may be more. I found this issue by trying to create a feature type with a field called "POINT". This failed with the following stack trace: java.util.EmptyStackException at java.base/java.util.Stack.peek(Unknown Source) at java.base/java.util.Stack.pop(Unknown Source) -- lots of ECQL stack trace removed for brevity -- at org.geotools.filter.text.ecql.ECQL.toExpression(ECQL.java:125) at org.geoserver.catalog.impl.AttributeTypeInfoImpl.getSource(AttributeTypeInfoImpl.java:147)
- Loading branch information
Showing
2 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/src/test/java/org/geoserver/catalog/impl/AttributeTypeInfoImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* (c) 2025 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.catalog.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class AttributeTypeInfoImplTest { | ||
@Test | ||
public void testQuoting() { | ||
assertNotQuoted("foo"); | ||
assertNotQuoted("foo123"); | ||
assertNotQuoted("FOO"); | ||
assertNotQuoted("FOO123"); | ||
assertNotQuoted("foo_bar"); | ||
assertNotQuoted("Foo_Bar"); | ||
|
||
assertQuoted("123foo"); | ||
assertQuoted("foo.bar"); | ||
assertQuoted("point"); | ||
assertQuoted("POINT"); | ||
assertQuoted("BBOX"); | ||
assertQuoted("intersects"); | ||
} | ||
|
||
private void assertNotQuoted(String name) { | ||
AttributeTypeInfoImpl a = new AttributeTypeInfoImpl(); | ||
a.setName(name); | ||
assertEquals(name, a.getSource()); | ||
} | ||
|
||
private void assertQuoted(String name) { | ||
AttributeTypeInfoImpl a = new AttributeTypeInfoImpl(); | ||
a.setName(name); | ||
assertEquals("\"" + name + "\"", a.getSource()); | ||
} | ||
} |