usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.85k stars 1.29k forks source link

[Bug] Issues parsing .bru files resulting in deleted contents #355

Open MatthewOwen01 opened 1 year ago

MatthewOwen01 commented 1 year ago

Under some circumstances the contents of script:pre-request can cause the file to be misinterpreted and overwritten when loaded.

Example. The following file will load successfully:

meta {
  name: courses
  type: http
  seq: 1
}

get {
  url: {{base_url}}/courses
  body: none
}

headers {
  Authorization: bearer {{auth_token}}
}

script:pre-request {
    const axios = require("axios");

    let resp = await axios({
      /*REMOVE ME*/method: "POST"
      ,url: bru.getEnvVar("auth_url")
      ,headers: {"authorization": "Bearer " + bru.getEnvVar("api_key")},
      data: ""
    });

    console.log(resp.data);
    bru.setVar('auth_token', resp.data);
}

However if the comment /*REMOVE ME*/ is removed, the file will not be loaded correctly and instead be replaced with:

meta {
  name: : courses
  type: http
  seq: NaN
}

post {
  url: : bru.getEnvVar("auth_url")
  body: none
}
lared commented 1 year ago

huh, I think this is another one of the bruno lang issues somewhat similar to #294 (although the other one just fails to load)