如何确定字符串是否已被 URL 编码? [英] How to find out if string has already been URL encoded?

查看:106
本文介绍了如何确定字符串是否已被 URL 编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查字符串是否已被编码?

How could I check if string has already been encoded?

例如,如果我编码 TEST==,我会得到 TEST%3D%3D.如果我再次编码最后一个字符串,我会得到 TEST%253D%253D,如果它已经被编码,我必须在这样做之前知道......

For example, if I encode TEST==, I get TEST%3D%3D. If I again encode last string, I get TEST%253D%253D, I would have to know before doing that if it is already encoded...

我已经保存了编码参数,我需要搜索它们.我不知道输入参数,它们将被编码或不编码,所以我必须知道在搜索之前是否必须对它们进行编码或解码.

I have encoded parameters saved, and I need to search for them. I don't know for input parameters, what will they be - encoded or not, so I have to know if I have to encode or decode them before search.

推荐答案

解码,对比原版.如果确实不同,则对原始文件进行编码.如果没有不同,则原始文件未编码.但它仍然没有说明新解码的版本是否仍在编码.递归的好任务.

Decode, compare to original. If it does differ, original is encoded. If it doesn't differ, original isn't encoded. But still it says nothing about whether the newly decoded version isn't still encoded. A good task for recursion.

希望不要用urlencode写一个quine,否则这个算法会卡住.

I hope one can't write a quine in urlencode, or this algorithm would get stuck.

例外:当字符串包含+"字符时,即使字符串不是 url 编码,url 解码器也会用空格替换它

Exception: When a string contains "+" character url decoder replaces it with a space even though the string is not url encoded

这篇关于如何确定字符串是否已被 URL 编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆