Skip to content
Snippets Groups Projects
Commit 239c7178 authored by gmantele's avatar gmantele
Browse files

[ADQL] Fix escaping of double quotes in delimited identifiers.

A delimited identifier is any sequence of characters between a pair of
double quotes. For instance: "123 I am a delimited identifier!".

It is of course possible to have double quotes inside this kind of identifier,
but they have to be doubled in order to not be mistaken with the end of the
identifier. For instance: "Cool ""identifier""".

However, this escape option was not taken into account by the ADQL library,
though the same mechanism was already in place for string contants.
parent 6ad03a80
Branches
No related tags found
No related merge requests found
......@@ -16,14 +16,16 @@ package adql.parser;
* You should have received a copy of the GNU Lesser General Public License
* along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2012 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
* Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI)
*/
import adql.query.IdentifierField;
import adql.query.TextPosition;
/**
* <p><b><u>Important:</u> This class is designed to be filled ONLY by {@link ADQLParser} !</b></p>
* <b><u>Important:</u> This class is designed to be filled ONLY by
* {@link ADQLParser}!</b>
*
* <p>This class is an array of maximum 4 {@link IdentifierItem}.</p>
* <p>
......@@ -31,26 +33,28 @@ import adql.query.TextPosition;
* which may be composed of more than only one identifier.
* </p>
* <p>
* For instance, a table can be referenced either by only its name or by the name of its schema and its name.
* So, in this last case there are 2 identifiers.
* For instance, a table can be referenced either by only its name or by the
* name of its schema and its name. So, in this last case there are 2
* identifiers.
* </p>
* <p>
* It is possible to get one by one each identifier item (by using the getters),
* or the concatenation of all (thanks to {@link #join(String)}).
* It is possible to get one by one each identifier item (by using the
* getters), or the concatenation of all (thanks to {@link #join(String)}).
* </p>
*
* @author Gr&eacute;gory Mantelet (CDS)
* @version 01/2012
* @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.4 (11/2017)
*
* see IdentifierItem
* @see IdentifierItem
*/
public class IdentifierItems {
/**
* Represent any ADQL identifier (column name, table name or table/column alias).
* Represent any ADQL identifier (column name, table name or table/column
* alias).
*
* @author Gr&eacute;gory Mantelet (CDS)
* @version 01/2012
* @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.4 (11/2017)
*/
public static class IdentifierItem {
public String identifier = null;
......@@ -58,7 +62,7 @@ public class IdentifierItems {
public TextPosition position = null;
public IdentifierItem(final Token token, final boolean caseSensitive){
identifier = token.image;
identifier = token.image.replaceAll("\"\"", "\"");
caseSensitivity = caseSensitive;
position = new TextPosition(token);
}
......
package adql.parser;
import static adql.parser.ADQLParserConstants.DELIMITED_IDENTIFIER;
import static adql.parser.ADQLParserConstants.REGULAR_IDENTIFIER;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import adql.parser.IdentifierItems.IdentifierItem;
public class TestIdentifierItem {
@BeforeClass
public static void setUpBeforeClass() throws Exception{}
@Before
public void setUp() throws Exception{}
@Test
public void testIdentifierItem(){
/* A regular identifier (with no special characters) should be returned
* as provided: */
IdentifierItem identifier = new IdentifierItem(new Token(REGULAR_IDENTIFIER, "m50"), false);
assertEquals("m50", identifier.toString());
/* Ensure doubled double quotes are escaped
* (i.e. considered as a single double quote): */
identifier = new IdentifierItem(new Token(DELIMITED_IDENTIFIER, "m50\"\""), true);
assertEquals("m50\"", identifier.toString());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment