Skip to content

Conversation

@Julian
Copy link

@Julian Julian commented Jun 7, 2023

Previously, trying to run e.g.:

http --json :4000/books title=שלום genre=bar author=baz yearPublished=2023 api-key:postmanrulz

i.e. POST to /books with:

{
    "title": "שלום",
    "genre": "bar",
    "author": "baz",
    "yearPublished": 2023
}

would blow up with:

HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Wed, 07 Jun 2023 16:24:11 GMT
Keep-Alive: timeout=5
content-length: 107
content-type: application/json; charset=utf-8

{
    "error": "Internal Server Error",
    "message": "Cannot read properties of null (reading '0')",
    "statusCode": 500
}

This error actually comes from the bad-words library during profanity
filtering, so it can actually be minimized to:

> var Filter = require('bad-words'),
...     filter = new Filter();
> filter.clean("שלום עליכם");
Uncaught TypeError: Cannot read properties of null (reading '0')
    at Filter.clean (/Users/julian/Development/library-api-v2/node_modules/.pnpm/bad-words@3.0.4/node_modules/bad-words/lib/badwords.js:58:41)

or even purely with JS regexes to:

/\b/.exec("שלום עליכם")

which just returns null because \b in JS doesn't cope with non-ASCII
word boundaries.

It seems slightly unlikely that bad-words would want some sort of
patch for this given it seems to only handle English anyhow (though
might file an issue anyhow in case it feels like at least doing nothing
in this case rather than blowing up).

But here, this patch makes us do the former, i.e. let through any
non-ASCII characters.

The test collection is also updated to make one of the fields actually
trigger this code path.

Julian added 2 commits June 7, 2023 14:16
Previously, trying to run e.g.:

    http --json :4000/books title=שלום genre=bar author=baz yearPublished=2023 api-key:postmanrulz

i.e. POST to /books with:

```json
{
    "title": "שלום",
    "genre": "bar",
    "author": "baz",
    "yearPublished": 2023
}
```

would blow up with:

```
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Wed, 07 Jun 2023 16:24:11 GMT
Keep-Alive: timeout=5
content-length: 107
content-type: application/json; charset=utf-8

{
    "error": "Internal Server Error",
    "message": "Cannot read properties of null (reading '0')",
    "statusCode": 500
}
```

This error actually comes from the bad-words library during profanity
filtering, so it can actually be minimized to:

```
> var Filter = require('bad-words'),
...     filter = new Filter();
> filter.clean("שלום עליכם");
Uncaught TypeError: Cannot read properties of null (reading '0')
    at Filter.clean (/Users/julian/Development/library-api-v2/node_modules/.pnpm/bad-words@3.0.4/node_modules/bad-words/lib/badwords.js:58:41)

```

or even purely with JS regexes to:

```
/\b/.exec("שלום עליכם")
```

which just returns `null` because `\b` in JS doesn't cope with non-ASCII
word boundaries.

It seems slightly unlikely that `bad-words` would want some sort of
patch for this given it seems to only handle English anyhow (though
might file an issue anyhow in case it feels like at least doing nothing
in this case rather than blowing up).

But here, this patch makes us do the former, i.e. let through any
non-ASCII characters.

The test collection is also updated to make one of the fields actually
trigger this code path.
{
"key": "testBookAuthor",
"value": "bar",
"value": "פלוני אלמוני",
Copy link
Author

Choose a reason for hiding this comment

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

(This says "John Doe" essentially FWIW)

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

Successfully merging this pull request may close these issues.

1 participant