Ruby:模糊测试所有 unicode 字符(UTF8/编码/字符串操作)
我无法迭代整个 unicode 字符范围。
我到处搜索...
我正在构建一个模糊器,并希望将所有 unicode 字符(一次一个)嵌入到 url 中。
例如: http://www.example.com?a=\uff1c
我知道有一些内置工具,但我需要更多的灵活性。
如果我可以做如下的事情: "\u" + "ff1c"
那就太好了。
这是我得到的最接近的结果:
char = "\u0000"
...
#within iteration
char.succ!
...
但是在字符 "\u0039"
(即数字 9)之后,我会得到“10”而不是“:”
I can't iterate over the entire range of unicode characters.
I searched everywhere...
I am building a fuzzer and want to embed into a url, all unicode characters (one at a time).
For example:http://www.example.com?a=\uff1c
I know that there are some built tools but I need more flexibility.
If i could do someting like the following: "\u" + "ff1c"
it would be great.
This is the closest I got:
char = "\u0000"
...
#within iteration
char.succ!
...
but after the character "\u0039"
, which is the number 9, I will get "10" instead of ":"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 pack 将数字转换为 UTF8 字符,但我不确定这是否可以解决您的问题。
您可以创建一个包含所有字符的数值的数组,然后使用 pack 来获取 UTF8 字符串,也可以从 0 循环到您需要的任何值,并在循环中使用 pack。
我写了一个小例子来解释自己。下面的代码打印出每个字符的十六进制值,后跟字符本身。
You could use pack to convert numbers to UTF8 characters but I'm not sure if this solves your problem.
You can either create an array with numeric values of all the characters and use pack to get an UTF8 string or you can just loop from 0 to whatever you need and use pack within the loop.
I've written a small example to explain myself. The code below prints out the hex value of each character followed by the character itself.
下面是一些更简单的代码,尽管有点混乱,但它利用了 Ruby 将在 << 右侧转换整数的事实。运算符到代码点。这仅适用于 Ruby 1.8 以上的整数值 <= 255。它适用于 1.9 中大于 255 的值。
Here's some simpler code, albeit slightly obfuscated, that takes advantage of the fact that Ruby will convert an integer on the right hand side of the << operator to a codepoint. This only works with Ruby 1.8 up for integer values <= 255. It will work for values greater than 255 in 1.9.