随机unicode插入到我的下划线模板中(random unicode being inserted in my underscore template)

因此,我的模板中插入了一些unicode,导致我的iframe src失败。

字符串似乎是javascript变量中的http://sand-dynamic.adpinr.com/social_stream/p_unit/1204042 ,但变成了

http://sand-dynamic.adpinr.com%e2%80%ac/social_stream/p_unit/1204042

显然但我不确定为什么。 我尝试在变量上执行此操作:

obj.URL = unescape(JSON.parse('"' + TL.getURL() + '/social_stream/p_unit/' + obj.id + '"');

但它似乎没有帮助。 我的模板只是称之为

<iframe frameborder="0" width="<%= width %>" height="<%= height %>" marginheight="0" marginwidth="0" target="_blank" scrolling="no" src="<%= URL %>"></iframe>

关于如何摆脱额外的unicode的任何想法? 它阻止我进入浏览器中的URL,而只是谷歌搜索它。 我宁愿让它动态删除任何额外的unicode,因为我不知道unicode是如何首先到达那里的。

So there is some unicode being inserted in my template and its causing my iframe src to fail.

The string appears to be http://sand-dynamic.adpinr.com/social_stream/p_unit/1204042 in the javascript variable, but turns into

http://sand-dynamic.adpinr.com%e2%80%ac/social_stream/p_unit/1204042

apparently but I'm not sure why. I tried to do this on the variable :

obj.URL = unescape(JSON.parse('"' + TL.getURL() + '/social_stream/p_unit/' + obj.id + '"');

But it didn't appear to help. My template just calls it like

<iframe frameborder="0" width="<%= width %>" height="<%= height %>" marginheight="0" marginwidth="0" target="_blank" scrolling="no" src="<%= URL %>"></iframe>

any thoughts on how I can get rid of that extra unicode? it's preventing me from going to the URL in the browser and it just googles it instead. I'd prefer to have it dynamically remove ANY extra unicode because I don't know how that unicode is getting there in the first place.

最满意答案

%e2%80%ac是U + 202C 。 不知何故,这个角色进入了你的URL变量。 该字符是不可见的,这就是为什么在打印出变量值时看不到它,但在字符串被URL编码时看到它。 您需要编辑字符串以删除该字符。 我无法提供更多信息,因为我不知道这个价值来自哪里。

如果你真的想要删除非ASCII范围字符,你总是可以这样做:

var url = ... var strippedURL = ''; for (var i = 0, l = url.length; i < l; i++){ if (url.charCodeAt(i) < 256) strippedURL += url[i]; } return strippedURL;

这不是解决这个问题的好方法。 如果你不知道char来自哪里,那么这只是你代码中其他地方需要修复的bug的标志。

%e2%80%ac is U+202C. Somehow that character got into your URL variable. That character is invisible, which is why you do not see it when you print out the value of your variable, but see it when the string is URLencoded. You need to edit the string to remove that character. I can't give more info because I don't know where that value is coming from.

If you really want to remove non-ASCII range chars, you could always do something like this:

var url = ... var strippedURL = ''; for (var i = 0, l = url.length; i < l; i++){ if (url.charCodeAt(i) < 256) strippedURL += url[i]; } return strippedURL;

That is not a good way to solve this though. If you don't know where that char is coming from, then that is just a sign that you have a bug somewhere else in your code that needs to be fixed.

随机unicode插入到我的下划线模板中(random unicode being inserted in my underscore template)

因此,我的模板中插入了一些unicode,导致我的iframe src失败。

字符串似乎是javascript变量中的http://sand-dynamic.adpinr.com/social_stream/p_unit/1204042 ,但变成了

http://sand-dynamic.adpinr.com%e2%80%ac/social_stream/p_unit/1204042

显然但我不确定为什么。 我尝试在变量上执行此操作:

obj.URL = unescape(JSON.parse('"' + TL.getURL() + '/social_stream/p_unit/' + obj.id + '"');

但它似乎没有帮助。 我的模板只是称之为

<iframe frameborder="0" width="<%= width %>" height="<%= height %>" marginheight="0" marginwidth="0" target="_blank" scrolling="no" src="<%= URL %>"></iframe>

关于如何摆脱额外的unicode的任何想法? 它阻止我进入浏览器中的URL,而只是谷歌搜索它。 我宁愿让它动态删除任何额外的unicode,因为我不知道unicode是如何首先到达那里的。

So there is some unicode being inserted in my template and its causing my iframe src to fail.

The string appears to be http://sand-dynamic.adpinr.com/social_stream/p_unit/1204042 in the javascript variable, but turns into

http://sand-dynamic.adpinr.com%e2%80%ac/social_stream/p_unit/1204042

apparently but I'm not sure why. I tried to do this on the variable :

obj.URL = unescape(JSON.parse('"' + TL.getURL() + '/social_stream/p_unit/' + obj.id + '"');

But it didn't appear to help. My template just calls it like

<iframe frameborder="0" width="<%= width %>" height="<%= height %>" marginheight="0" marginwidth="0" target="_blank" scrolling="no" src="<%= URL %>"></iframe>

any thoughts on how I can get rid of that extra unicode? it's preventing me from going to the URL in the browser and it just googles it instead. I'd prefer to have it dynamically remove ANY extra unicode because I don't know how that unicode is getting there in the first place.

最满意答案

%e2%80%ac是U + 202C 。 不知何故,这个角色进入了你的URL变量。 该字符是不可见的,这就是为什么在打印出变量值时看不到它,但在字符串被URL编码时看到它。 您需要编辑字符串以删除该字符。 我无法提供更多信息,因为我不知道这个价值来自哪里。

如果你真的想要删除非ASCII范围字符,你总是可以这样做:

var url = ... var strippedURL = ''; for (var i = 0, l = url.length; i < l; i++){ if (url.charCodeAt(i) < 256) strippedURL += url[i]; } return strippedURL;

这不是解决这个问题的好方法。 如果你不知道char来自哪里,那么这只是你代码中其他地方需要修复的bug的标志。

%e2%80%ac is U+202C. Somehow that character got into your URL variable. That character is invisible, which is why you do not see it when you print out the value of your variable, but see it when the string is URLencoded. You need to edit the string to remove that character. I can't give more info because I don't know where that value is coming from.

If you really want to remove non-ASCII range chars, you could always do something like this:

var url = ... var strippedURL = ''; for (var i = 0, l = url.length; i < l; i++){ if (url.charCodeAt(i) < 256) strippedURL += url[i]; } return strippedURL;

That is not a good way to solve this though. If you don't know where that char is coming from, then that is just a sign that you have a bug somewhere else in your code that needs to be fixed.