Skip to content

Escaping characters in loaded script from console #843

Closed

Description

@gramian

ArcadeDB Version: v23.1.2 (build 9dbe3ce/1675373316135/main)

JDK Version: openjdk 11.0.18 2023-01-17

OS: MacOS 12.6

Escaping characters is done in the console terminal or studio commands with \, for example \\. When loading a script from console one needs \\\\ to escape \. For loading scripts the BufferedReader is used in the console (executeLoad): https://github.com/ArcadeData/arcadedb/blob/main/console/src/main/java/com/arcadedb/console/Console.java#L668 which I believe is the source of this different (and strange) behavior. The general issue is explained here, too: https://coderanch.com/t/277390/java/reading-file-BufferedReader .

Expected behavior

Same behavior as in console (keyboard input) or studio.

Actual behavior

Escaped characters need extra escape slashes

Steps to reproduce

This works from console or studio, but not from script:

CREATE DOCUMENT TYPE doc;
CREATE PROPERTY doc.uri STRING (regexp '^([a-zA-Z]{1,15}:)(\\/\\/)?[^\\s\\/$.?#].[^\\s]*$');

This works when loading from a script:

CREATE DOCUMENT TYPE doc;
CREATE PROPERTY doc.uri STRING (regexp '^([a-zA-Z]{1,15}:)(\\\\/\\\\/)?[^\\\\s\\\\/$.?#].[^\\\\s]*$');

Activity

  1. gramian commented on Feb 8, 2023

    @gramian
    CollaboratorAuthor

    @lvca I thought about replacing in the loaded file, before passing it into the BufferedReader, to replace \\ with \\\\. AFAIK This seems only possible by converting the File instance to a string, which does not make sense if a BufferedReader is to be used. I don't have enough Java knowledge to fix this, sorry.

  2. added this to the 23.2.1 milestone on Feb 8, 2023
  3. lvca commented on Feb 8, 2023

    @lvca
    Member

    Reproduced with a new test case:

    ArcadeDB Console v.23.2.1-SNAPSHOT - Copyrights (c) 2021 Arcade Data Ltd (https://arcadedb.com)
    Database 'console' created
    Database 'console' connected
    Executing commands from file src/test/resources/console-batch.sql...
    {console}> CREATE DOCUMENT TYPE doc
    +---------+--------------------+
    |NAME     |VALUE               |
    +---------+--------------------+
    |operation|create document type|
    |typeName |doc                 |
    +---------+--------------------+
    Command executed in 155ms
    {console}> CREATE PROPERTY doc.uri STRING (regexp '^([a-zA-Z]{1,15}:)(\/\/)?[^\s\/$.?#].[^\s]*$')
    ERROR:
    com.arcadedb.exception.CommandSQLParsingException: CREATE PROPERTY doc.uri STRING (regexp '^([a-zA-Z]{1,15:)(\/\/)?[^\s\/$.?#].[^\s]*$')
    
  4. lvca commented on Feb 8, 2023

    @lvca
    Member

    New test case for this:

    @Test
    public void testLoad() throws IOException {
      Assertions.assertTrue(console.parse("connect " + DB_NAME));
      Assertions.assertTrue(console.parse("load " + new File("src/test/resources/console-batch.sql")));
    
      final String[] urls = new String[] { "http://arcadedb.com", "https://www.arcadedb.com", "file://this/is/myfile.txt" };
    
      // VALIDATE WITH PLAIN JAVA REGEXP FIRST
      for (String url : urls)
        Assertions.assertTrue(url.matches("^([a-zA-Z]{1,15}:)(\\/\\/)?[^\\s\\/$.?#].[^\\s]*$"), "Cannot validate URL: " + url);
    
      // VALIDATE WITH DATABASE SCHEMA
      for (String url : urls)
        console.getDatabase().newDocument("doc").set("uri1", url).validate();
    }
  5. lvca commented on Feb 8, 2023

    @lvca
    Member

    Fixed.

  6. gramian commented on Feb 8, 2023

    @gramian
    CollaboratorAuthor

    My test works too now. Cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions