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

Add test object with URLs as properties (that have periods . in them) #19

Open
dlongley opened this issue May 14, 2018 · 4 comments
Open
Assignees

Comments

@dlongley
Copy link
Member

Previous versions of MongoDB required that properties in documents that have periods . in them needed to be escaped. I suspect this hasn't changed. We have some encode/decode functions in bedrock-mongodb to handle this:

https://github.com/digitalbazaar/bedrock-mongodb/blob/master/lib/index.js#L380-L449

But we may not be using them here for object data in records in operations or in state machine storage. We should add a test that includes properties that would cause such an error and make sure we're covered through the process. We may have to add some encode/decode functions somewhere.

@mattcollier
Copy link
Contributor

mattcollier commented Aug 23, 2018

Attempting to insert an operation like this does result in an uncaught error:

{
  '@context': 'https://example.com/somecontext',
  type: 'CreateWebLedgerRecord',
  record: {
    '@context': 'https://example.com/somecontext',
    'property.dot.annotation': false,
    // id: intentionally omitted
    type: 'Concert',
    name: 'Primary Event',
    startDate: '2017-07-14T21:30',
    location: 'https://example.org/the-venue-new-york',
    offers: {
      type: 'Offer',
      price: '13.00',
      priceCurrency: 'USD',
      url:
        `https://example.org/purchase/a05bebf8-c966-427f-92f2-ff9060f4bd23`,
    }
  },
  proof: {
    type: 'RsaSignature2018',
    created: '2017-05-10T19:47:13Z',
    creator: "https://bedrock.local:18443/consensus/continuity2017/voters/57565658-0d8a-4668-b734-e801aeaa6472#key",
    jws: "nlx8c9uFI8Ur/h57F5AeHHrKPSKiiGJmN6APRnYesQPK4LXftnm2lzqpWzsvKGDPzH6QfoOIktQu2Ax0pj/Bi6Oa4/Na75HuoRGppaHCqlyrgbr5EUPRCiYSjlsYKBhEN6ITdmR/O8iGz9WZi4PQjSW9XrrP8bQLeu9Kzsu5hdkzmgS4f3PCXpImwpKFttyF7xARvSQxrgRxZrqWPIGtD9sghRY2/Zn3T2npTaOTXMhgW9Lc7uEpjThnCEsrKflshbLGevZglc/njBp5SoEgon8CuzQIkMBFjCTEdJYBtTuk0AF5BcVyoxPDfH9bdUYOIMFaDhZBQKM5tQEU2GqE/g=="
  }
}
     Uncaught Error: key property.dot.annotation must not contain '.'
      at serializeInto (node_modules/bson/lib/bson/parser/serializer.js:913:19)
      at serializeObject (node_modules/bson/lib/bson/parser/serializer.js:347:18)
      at serializeInto (node_modules/bson/lib/bson/parser/serializer.js:937:17)
      at serializeObject (node_modules/bson/lib/bson/parser/serializer.js:347:18)
      at serializeInto (node_modules/bson/lib/bson/parser/serializer.js:937:17)
      at serializeObject (node_modules/bson/lib/bson/parser/serializer.js:347:18)
      at serializeInto (node_modules/bson/lib/bson/parser/serializer.js:727:17)
      at serializeObject (node_modules/bson/lib/bson/parser/serializer.js:347:18)
      at serializeInto (node_modules/bson/lib/bson/parser/serializer.js:937:17)
      at BSON.serialize (node_modules/bson/lib/bson/bson.js:63:28)

@davidlehn
Copy link
Member

This may lead to performance issues due to added encode/decode calls. Should consider only applying the transformations to the unknown data fields such as record.

@mattcollier
Copy link
Contributor

A bit more info to add here. The node mongo v3.1.3 driver produces the same error with mongodb server v3.6.7

Error: key some.dot.notation must not contain '.'
    at serializeInto (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/parser/serializer.js:914:19)
    at serializeObject (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/parser/serializer.js:348:18)
    at serializeInto (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/parser/serializer.js:728:17)
    at serializeObject (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/parser/serializer.js:348:18)
    at serializeInto (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/parser/serializer.js:938:17)
    at BSON.serialize (/home/matt/dev/loop-bench/node_modules/bson/lib/bson/bson.js:63:28)
    at Query.toBin (/home/matt/dev/loop-bench/node_modules/mongodb-core/lib/connection/commands.js:145:25)
    at serializeCommands (/home/matt/dev/loop-bench/node_modules/mongodb-core/lib/connection/pool.js:1044:43)
    at Pool.write (/home/matt/dev/loop-bench/node_modules/mongodb-core/lib/connection/pool.js:1260:3)
    at executeWrite (/home/matt/dev/loop-bench/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:147:10)

It's unfortunate that this error is not being rethrown in such a way that includes some sort of error code. Even still, we could conceivably catch the error, check the message for must not contain '.' and act accordingly. Probably a helper isDotAnnotationError(err) would do the trick. Then we would know that the record needs to be manipulated before trying again.

@davidlehn
Copy link
Member

@mattcollier For that to work there would have to also be some extra metadata stored to indicate data was encoded so that encode/decode could be properly paired up.

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