Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection name with dash (-) symbol raises reference error on JavaScript shell arangosh #497

Closed
ghost opened this issue Apr 30, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 30, 2013

OS version: Ubuntu 12.10

Shell version:

Welcome to arangosh 1.2.3. Copyright (c) triAGENS GmbH
Using Google V8 3.16.14 JavaScript engine, READLINE 6.2, ICU 4.8.1.1

Connected to ArangoDB 'tcp://localhost:8529' version 1.2.3

Steps to recreate:

arangosh> db._createEdgeCollection("has-emails");
[ArangoCollection 21131514, "has-emails" (type edge, status loaded)]

arangosh> db.has-emails
JavaScript exception in file '(shell)' at 1,8: ReferenceError: emails is not defined
!db.has-emails
! ^
stacktrace: ReferenceError: emails is not defined
at (shell):1:8

Collections without a dash (-) symbol works well.

arangosh> db.has_emails
[ArangoCollection 22835450, "has_emails" (type edge, status loaded)]

arangosh> db.entity
[ArangoCollection 9597178, "entity" (type document, status loaded)]

@F21
Copy link

F21 commented Apr 30, 2013

Because has-emails is not valid dot notation syntax for accessing properties in javascript, you can use this alternative syntax (brackets) to access properties that cannot be access using dot notation:

arangosh> db['has-emails']
[ArangoCollection 128359072782, "has-emails" (type edge, status loaded)]

@jsteemann
Copy link
Contributor

I agree to @F21. You can create a collection with a name that contains a dash in ArangoDB.
However, using the dash name unquoted will lead to the dash being interpreted as the symbol for an arithmetic minus, and in the following leading to a JavaScript error.

This has nothing to do with ArangoDB, but is a feature of the JavaScript language. The language disallows using special characters such as the dash in identifier names.
That means you must not use something like obj.my-variable in Javascript, but instead you should use obj['my-variable'].

@ghost
Copy link
Author

ghost commented May 2, 2013

In my humble opinion, we should then not allow collection names with the underscore (_), or the dash (-) symbol . It is not consistent.

https://github.com/triAGENS/ArangoDB/wiki/NamingConventions

@F21
Copy link

F21 commented May 2, 2013

The underscore is needed though, because they are used for naming system collections, like _users.

@jsteemann
Copy link
Contributor

The underscore is actually allowed in JavaScript identifiers, too.
You can use variable names such as _foo or even _ in JavaScript. There is even a JS library named underscore, and the convention is to reference the library from a variable named _.

And I think there is no problem with allowing the dash for collection names, too.
You have to make sure that you properly quote the table names, as you would in any other database.
You also want to make sure you properly quote names when putting parameters into URLs or into strings. Otherwise you're vulnerable to parameter injection etc.

Btw. in Javascript you can even have attribute names such as

"foo" & "bar"

by using them properly quoted:

a = { "\"foo\" & \"bar\"" : "some value" };
a["\"foo\" & \"bar\""];

@frankmayer
Copy link
Contributor

Also, underscore is widely used for naming tables and fields in databases 😄 ,so if it's not an issue like the dash is, maybe we should probably let this one pass (even if it's not consistent 😄 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants