Skip to content
代码片段 群组 项目
提交 c0425241 编辑于 作者: Stan Hu's avatar Stan Hu
浏览文件

Fix obsoleted URI.{encode,decode} calls for Ruby 2.7

Attempting to use these calls results in these obsolete warnings:

```
warning: URI.escape is obsolete
```

As mentioned by the Knapsack Pro blog:

>>>
The trouble with a concept of “escaping the URI” is that URI consists of
many components (like path or query), and we don’t want to escape them
in the same way. For example, it’s fine for a # character to appear at
the end of the URI (when it’s used as what’s usually called an anchor,
or in URI parlance - a fragment component) - but when the same # is part
of user’s input (like in a search query), we want to encode it to ensure
correct interpretation. Similarly, if the query string value contains
other reserved characters, like = or &, we do want to escape them so
that they are not incorrectly interpreted as delimiters, as if they were
used as reserved characters.

URI.escape relies on a simple gsub operation for the whole string and
doesn’t differentiate between distinct components, which doesn’t take
into account intricacies like those mentioned above.
>>>

CGI.escape and CGI.encode_www_form_component are often mentioned as
replacements, but both substitute spaces for `+` instead of `%20`. This
doesn't work for Grafana. Using `%20` for spaces everywhere is valid,
which is what `Addressable::URI` does.
上级 d487b9e2
No related branches found
No related tags found
无相关合并请求
加载中
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册