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

UTF-8 characters in response returns malformed data #23

Closed
rmtsrc opened this issue Mar 19, 2019 · 1 comment · Fixed by #24
Closed

UTF-8 characters in response returns malformed data #23

rmtsrc opened this issue Mar 19, 2019 · 1 comment · Fixed by #24

Comments

@rmtsrc
Copy link
Contributor

rmtsrc commented Mar 19, 2019

For example having the following setup and tapes:

index.js

const talkback = require("talkback");

const opts = {
  host: "https://example.com",
};
const server = talkback(opts);
server.start(() => console.log("Talkback Started"));

tapes/quotes.json5

{
    meta: {
        createdAt: '2019-03-19T22:03:41.814Z',
        host: 'https://example.com',
        resHumanReadable: true,
    },
    req: {
        url: '/test.json',
        method: 'GET',
        headers: {
            accept: '*/*',
            'user-agent': 'curl',
        },
        body: '',
    },
    res: {
        status: 200,
        headers: {
            'content-type': [
                'application/json; charset=UTF-8',
            ],
            date: [
                'Tue, 19 Mar 2019 22:03:42 GMT',
            ],
            expires: [
                'Tue, 26 Mar 2019 22:03:42 GMT',
            ],
            'last-modified': [
                'Tue, 19 Mar 2019 22:00:27 GMT',
            ],
            'content-length': [
                '46',
            ],
            connection: [
                'close',
            ],
        },
        body: {
            words: 'in special “quotes” break',
        },
    },
}

node index.js

curl -v -H 'User-Agent: curl' http://localhost:8080/test.json

Returns

* Excess found in a non pipelined read: excess = 4, size = 42, maxdownload = 42, bytecount = 0

{
  "words": "in special “quotes” brea

tapes/emojis.json5

{
    meta: {
        createdAt: '2019-03-19T22:03:41.814Z',
        host: 'https://example.com',
        resHumanReadable: true,
    },
    req: {
        url: '/test2.json',
        method: 'GET',
        headers: {
            accept: '*/*',
            'user-agent': 'curl',
        },
        body: '',
    },
    res: {
        status: 200,
        headers: {
            'content-type': [
                'application/json; charset=UTF-8',
            ],
            date: [
                'Tue, 19 Mar 2019 22:03:42 GMT',
            ],
            expires: [
                'Tue, 26 Mar 2019 22:03:42 GMT',
            ],
            'last-modified': [
                'Tue, 19 Mar 2019 22:00:27 GMT',
            ],
            'content-length': [
                '33',
            ],
            connection: [
                'close',
            ],
        },
        body: {
            emojis: 'also 😢 break',
        },
    },
}

curl -v -H 'User-Agent: curl' http://localhost:8080/test2.json

Returns

* Excess found in a non pipelined read: excess = 2, size = 31, maxdownload = 31, bytecount = 0

{
  "emojis": "also 😢 break"

Notice how the response is malformed and missing the closing brackets and objects.

A workaround is to remove the response content-length.

@ijpiantanida
Copy link
Owner

Hi @sebflipper, I just released v1.10.0 which includes this fix.
Thanks for the contribution.

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 a pull request may close this issue.

2 participants