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

Using a dash '-' as part of an entity zone leads to strange behavior (at least using seneca-mongo-store) #48

Open
jeromevalentin opened this issue Feb 24, 2018 · 0 comments

Comments

@jeromevalentin
Copy link

jeromevalentin commented Feb 24, 2018

The code below should create a collection: 'base_collectionName' in the database associated with zone 'foo-bar'.

let entity = seneca.make('foo-bar', 'base', 'collectionName') 
entity.save$()

Unfortunately, the method parsecanon() in make_entity.js is handling it with a regular expression considering '-' as the empty value of one part of the canon. So the canon which should be

{ zone: 'foo-bar', base: 'base', name: 'collectionName' } 

is not parsed like that and produces

{ zone: '-', base: '-', name: 'foo'}.

I recommend to change the regular expression used in parsecanon as follow to workaround this issue:

...
  var m = /\$?(((?:\w|-)+|-)\/)?((\w+|-)\/)?(\w+|-)/.exec(str)
  if (m) {
    var zi = m[4] == null ? 4 : 2
    var bi = m[4] == null ? 2 : 4
...

By the way, the acceptable character set per zone/base/name are dependent of the underlying database.
So I would recommend to make the different part of the regular expression customizable in order to simplify the integration of seneca-entity on existing databases.

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

1 participant