浏览器是否发送“ "?或“ "还是取决于浏览器? [英] Do browsers send " " or " " or does it depend on the browser?

查看:35
本文介绍了浏览器是否发送“ "?或“ "还是取决于浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题困扰了我一百万年......每当我创建一个带有允许多行的文本区域的网站(例如用户个人资料的Bio")时,我总是最终编写以下偏执代码:

This question has bothered me for a million years... whenever I create a website with a textarea that allows multi-line (such as a "Bio" for a user's profile) I always end up writing the following paranoid code:

// C# code sample...
bio = bio.Replace("
", "
").Replace("
", "
");
bio = Regex.Replace(@"
{2,}", "

");

那么,如果 <textarea name="Bio"></textarea> 有多行,浏览器会发送什么?

So, what do browsers send up for a <textarea name="Bio"></textarea> if it has multiple lines?

推荐答案

HTTPMIME 规范指定标题行必须以 结尾,但它们不清楚(有些人会争论不清楚他们是否清楚)关于如何处理 TEXTAREA 的内容.(例如,参见 这个话题来自一个关于这个问题的 HTML 工作组.)

The HTTP and MIME specs specify that header lines must end with , but they aren't clear (some would argue that it isn't clear if they are clear) about what to do with the contents of a TEXTAREA. (See, for instance, this thread from an HTML working group about the issue.)

这是 HTTP/1.1 规范中关于消息头的引用:

Here's a quote from the HTTP/1.1 spec about message headers:

消息头字段的行终止符是序列 CRLF.但是,我们建议应用程序在解析此类标头时,将单个 LF 识别为行终止符并忽略前导 CR.

The line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR.

我认为总的来说这是一个很好的策略:对你生产的东西严格,但对你接受的东西放宽.您应该假设您将收到各种线路终止符.(注意除了 CRLF 和 LF,Mac OS-9 单独使用了 CR,周围还有一些.Unicode 标准(第 5.8 节)指定了应被识别为行终止符的各种字符序列;有一个列表 此处.)

I think that is a good strategy in general: be strict about what you produce but liberal in what you accept. You should assume that you will receive all sorts of line terminators. (Note that in addition to CRLF and LF, Mac OS-9 used CR alone, and there are still a few of those around. The Unicode standard (section 5.8) specifies a wide range of character sequences that should be recognized as line terminators; there's a list of them here.)

这篇关于浏览器是否发送“ "?或“ "还是取决于浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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