- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想在对象上使用 querystring.stringify。对字符串的要求有点不合标准,星号、斜杠和撇号都需要转义。 Querystring 不会转义这些(它们通常不需要)但是文档说 querystring.escape 是专门公开的,以便我们可以用我们自己的函数覆盖它。以下内容对我有用:
querystring.escape = function(str) {
str = encodeURIComponent(str)
.replace(/\*/g, '%2A')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/'/g, '%27');
return str;
};
我唯一担心的是,如果我理解正确,这可能会改变其他模块的行为,这些模块将来可能也需要查询字符串(具有正常的转义函数)。 node.js 文档说模块只加载一次,原始实例返回给后续的 require 调用。有没有办法强制这个特定的查询字符串实例是唯一的?
显然,我可以编写一个包装器,在常规调用 querystring.stringify 之后进行替换,但我很好奇,因为标准 Node 模块真的有一个“全局”设置对我来说似乎很奇怪,除非有毕竟,实际上是某种需要唯一实例的方法。
最佳答案
Is there a way for me to force this particular instance of querystring to be unique?
不是真的。 Node 的 module caching是每个进程并且 based on the module's filepath .
更改不会跨入/跨出 Child Processes或 Clusters .因此,您可以通过其中之一将脚本与其自己的 querystring
隔离。
但是,在同一个进程中,Node 没有提供官方方法来绕过它来为单个模块检索唯一实例。
this might change the behavior of other modules that might also require querystring (with its normal escape function) in the future.
好吧,如果 URL 编码的值有额外的编码字符,它仍然有效。只是通常他们不需要。
而且,我想,有可能影响将期望放在编码值上的模块。但是,这通常是一个奇怪的选择(异常(exception)情况是对您自己的 querystring.escape
进行单元测试)。所以,只要能正常解码,应该没问题。
querystring.escape = function (str) { /* ... */ }; // your function here
var sample = "a(b*c)'d";
var encoded = querystring.escape(sample);
console.log(encoded); // a%28b%2ac%29'd
var decoded = querystring.unescape(encoded);
console.log(decoded); // a(b*c)'d
console.log(decoded === sample); // true
并且,能够覆盖 querystring.escape
和 querystring.unescape
是设计使然:
The escape function used by
querystring.stringify
, provided so that it could be overridden if necessary.
关于javascript - 在单个模块中覆盖 node.js querystring.escape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17983532/
我喜欢使用 Python 的 SimpleHTTPServer 来本地开发各种需要通过 Ajax 调用等方式加载资源的 Web 应用程序。 当我在我的 URL 中使用查询字符串时,服务器总是重定向到相
我们正在使用 Swagger/Swashbuckle 生成 OpenApi 定义。然后将此定义导入到 Azure API 管理中。 我们在 get 请求中有一些我们标记为必需的查询字符串参数。我们的验
我有一个带有查询字符串的页面请求,例如http://www.xyz.net/Orders.aspx?OrderID=1。该页面显示在浏览器中。现在页面上有一个 asp:LinkButton ,它应
我们有以下重写规则: RewriteRule ^([A-Za-z0-9\_]+)$ index.php?rewrite=$1 [L,QSA] 我们想知道是否有一种方法可以让 ?rewrite=$1
我们有以下重写规则: RewriteRule ^([A-Za-z0-9\_]+)$ index.php?rewrite=$1 [L,QSA] 我们想知道是否有一种方法可以让 ?rewrite=$1
我需要http://profiles.mysite.com/Me显示什么http://mysite.com/profile.php?user=Me会显示。 “我”根据用户名而变化。它可以包含空格并且不
我正在努力实现以下条件 orgId =“z2store”,类型 =“web”,日期时间 =“12:17:08” 下面是我写的查询 GET /sample/_search { "bool" : {
我有一个网址: http://mywebsite.com/Account/?Number=25191108&Name=Something&Remote=False 我想重定向到: http://ano
是否可以在回发时附加到查询字符串?如果是,您到底是怎么做到的? 谢谢! 最佳答案 据我所知不是。您对 ASP.NET 的回发没有太多控制。对于另一种类型的应用程序,您可以发布到另一个页面。我知道在 a
我在一个支付平台上工作,为了响应支付,一个简单的 GET 调用,在查询字符串中有一些参数,是对我的听众的: http://localhost/mytest/listener?TIMECREATED=0
方法一: 在 JavaScript 中,可以使用 URLSearchParams 对象来处理 URL 中的查询字符串. 序列化(将 JavaScript 对象转换为查询字符串)可以使用 URLSe
一,开篇分析 这篇文章把这三个模块拿来一起说,原因是它们各自的篇幅都不是很长,其次是它们之间存在着依赖关系,所以依次介绍并且实例分析。废话不多说了,请看下面文档: (1),"Url模块
我想将查询字符串附加到页面内的所有动态链接上 - 以修复旧版本中的错误 - 这可能吗? 有什么想法吗? 最佳答案 类似这样的吗? var querystring = 'myquerystringtoa
我使用以下代码从 LogIn.aspx 获取 LogedInUser 并将其发送到 Chat.aspx 然后将其发送到 FrmForAjaxCalls 从 Db 返回数据并将其填充到 div 上,但在
我今天在 Web 应用程序中重构一些代码,并在所有网页的基类中遇到了类似的内容: if (Request.QueryString["IgnoreValidation"] != null) {
我想创建一个联系人页面, 我有以下代码: #:Name# #:Surname# 还有两个值(contactNumber 和 Email) 在第一个 View 中,我只显示名称,我想在单击时
大家早上好, 我有一个系统,需要发送一封电子邮件,其中包含我在 JS 中的一些变量。代码一开始对我来说看起来不错,但是 Request.QueryString 没有返回任何内容。我正在尝试使用 Req
在 aspx 页面中我有 anchor 标记。我的 URL 已经有我想重用的 Id 参数。要求是将用户重定向到具有当前 url id 的提及页面,例如 "~/Dir/Home?Id=" & Reque
我使用 request.querystring 只是为了访问我从一个页面传递到另一个页面的参数。 它给了我一个错误。 Non-invocable member 'System.Web.HttpRequ
此问题与上一个问题相关 Passing Variable from page to page using ASP.NET (C#) without using QueryString 我的情况的不同之
我是一名优秀的程序员,十分优秀!