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

Improve the stability of the tokenizer #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
},
"devDependencies": {
"@ipld/garbage": "^6.0.0",
"aegir": "^45.0.1"
"aegir": "^45.0.7",
"eslint-config-ipfs": "^7.0.6",
"eslint-plugin-n": "^17.14.0"
Comment on lines +170 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aegir should be contributing what it needs for linting, no? does it fail without these?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does fails without on my side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try removing these and push again, this changeset works for me locally without them and pushing a new commit might wake CI up, something odd going in GitHub Actions even after a re-start attempt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ npm ls --all | grep 'eslint-config-ipfs\|eslint-plugin-n'
│ │ ├─┬ eslint-config-ipfs@7.0.6
│ │ │ ├─┬ eslint-plugin-n@16.6.2
│ │ │ ├── eslint-plugin-n@16.6.2 deduped
│ │ ├── eslint-plugin-no-only-tests@3.3.0
│ │ ├── eslint-plugin-node@11.1.0 deduped
│ ├─┬ eslint-plugin-node@11.1.0

this is from a freshly installed tree without them, so they're there already from aegir.

}
}
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,26 @@ class DagJsonTokenizer extends cborgJson.Tokenizer {
next () {
const token = this._next()

if (token.type === Type.map) {
if (token.type.compare(Type.map) === 0) {
const keyToken = this._next()
if (keyToken.type === Type.string && keyToken.value === '/') {
if (keyToken.type.compare(Type.string) === 0 && keyToken.value === '/') {
const valueToken = this._next()
if (valueToken.type === Type.string) { // *must* be a CID
if (valueToken.type.compare(Type.string) === 0) { // *must* be a CID
const breakToken = this._next() // swallow the end-of-map token
if (breakToken.type !== Type.break) {
if (breakToken.type.compare(Type.break)) {
throw new Error('Invalid encoded CID form')
}
this.tokenBuffer.push(valueToken) // CID.parse will pick this up after our tag token
return new Token(Type.tag, 42, 0)
}
if (valueToken.type === Type.map) {
if (valueToken.type.compare(Type.map) === 0) {
const innerKeyToken = this._next()
if (innerKeyToken.type === Type.string && innerKeyToken.value === 'bytes') {
if (innerKeyToken.type.compare(Type.string) === 0 && innerKeyToken.value === 'bytes') {
const innerValueToken = this._next()
if (innerValueToken.type === Type.string) { // *must* be Bytes
if (innerValueToken.type.compare(Type.string) === 0) { // *must* be Bytes
for (let i = 0; i < 2; i++) {
const breakToken = this._next() // swallow two end-of-map tokens
if (breakToken.type !== Type.break) {
if (breakToken.type.compare(Type.break)) {
throw new Error('Invalid encoded Bytes form')
}
}
Expand Down
Loading