mean-expert-official / loopback-sdk-builder

Tool for auto-generating Software Development Kits (SDKs) for LoopBack
Other
399 stars 175 forks source link

Filter on headers should check whether values are valid or not before setting headers #520

Closed dreamdevil00 closed 6 years ago

dreamdevil00 commented 7 years ago

What type of issue are you creating?

What version of this module are you using?

Write other if any:

Please add a description for your issue:

I have to get infomation count with where filter, and the filter is

{
  "and": [{
    "or": [{
        "yearno": {
          "like": "2010",
          "options": "i"
        }
      },
      {
        "siteName": {
          "like": "2010",
          "options": "i"
        }
      }
    ]
  }]
}

it turns out one url

demoApi/count?where[and][0][or][0][yearno][like]=2010&where[and][0][or][0][yearno][options]=i&where[and][0][or][1][siteName][like]=2010&where[and][0][or][1][siteName][options]=i

which does not work at all

Instead, I think the url should be like this

demoApi/count?where={"and":[{"or":[{"yearno":{"like":"2010","options":"i"}},{"siteName":{"like":"2010","options":"i"}}]}]}

Please confirm

dreamdevil00 commented 7 years ago

Finally, I found the problem. This problem occoured when the the search value is Chinese.

Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '{"where":{"and":[{"or":[{"pname":"2010年四项目"}]}]},"limit":20,"offset":0,"order":""}' is not a valid HTTP header field value."

I found the default behavior of filter is filter on headers in lb.config.ts When I changed

private static filterOn: string = 'headers';

to

private static filterOn: string = 'url';

the problem gone.

I found that it does not check the value before setting headers, the source code, this leads to the problem.

jonathan-casarrubias commented 6 years ago

@dreamdevil00 you should not directly modify the lb.config file, you should instead call the method LoopBackConfig.filterOnUrl() to avoid the headers issue.

Cheers Jon

dreamdevil00 commented 6 years ago

Thanks a lot. @jonathan-casarrubias