char0n/http-request-in-editor

Input without empty lines is not parsing.

vitaliy-sk opened this issue · 3 comments

Describe the bug
Input without empty lines at the end is not parsing.
Simple input like GET https://test.com returns an empty array

To Reproduce

const { parse } = require('http-request-in-editor')


// Working
let input = `GET https://ifconfig.co/json` + '\n\n'

// NOT Working
let input = `GET https://ifconfig.co/json`

const cst = parse(input);
console.log(JSON.stringify(cst))

Expected behavior
CST is returned for input without empty lines at the end of the input

Thanks I have a look.

I was wondering - what's your usecase for using this library?

Thanks I have a look.

I was wondering - what's your usecase for using this library?

Thanks, I'm investigating different options to implement standalone Inteliji like API client

@vitaliy-sk I investigated and determined that the current behavior is correct.

request requires a new-line terminal to follow immediately after request-line. Without it, the ambiguity will appear. This parser is a canonical implementation of the http-request-in-editor specification.

Check the corpus for more examples.

I guess what we could possibly do is to inject CRFL at the end of the source string if it doesn't have one.