source: trip-planner-front/node_modules/engine.io/build/transports/polling-jsonp.js@ 84d0fbb

Last change on this file since 84d0fbb was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[e29cc2e]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.JSONP = void 0;
4const polling_1 = require("./polling");
5const qs = require("querystring");
6const rDoubleSlashes = /\\\\n/g;
7const rSlashes = /(\\)?\\n/g;
8class JSONP extends polling_1.Polling {
9 /**
10 * JSON-P polling transport.
11 *
12 * @api public
13 */
14 constructor(req) {
15 super(req);
16 this.head = "___eio[" + (req._query.j || "").replace(/[^0-9]/g, "") + "](";
17 this.foot = ");";
18 }
19 /**
20 * Handles incoming data.
21 * Due to a bug in \n handling by browsers, we expect a escaped string.
22 *
23 * @api private
24 */
25 onData(data) {
26 // we leverage the qs module so that we get built-in DoS protection
27 // and the fast alternative to decodeURIComponent
28 data = qs.parse(data).d;
29 if ("string" === typeof data) {
30 // client will send already escaped newlines as \\\\n and newlines as \\n
31 // \\n must be replaced with \n and \\\\n with \\n
32 data = data.replace(rSlashes, function (match, slashes) {
33 return slashes ? match : "\n";
34 });
35 super.onData(data.replace(rDoubleSlashes, "\\n"));
36 }
37 }
38 /**
39 * Performs the write.
40 *
41 * @api private
42 */
43 doWrite(data, options, callback) {
44 // we must output valid javascript, not valid json
45 // see: http://timelessrepo.com/json-isnt-a-javascript-subset
46 const js = JSON.stringify(data)
47 .replace(/\u2028/g, "\\u2028")
48 .replace(/\u2029/g, "\\u2029");
49 // prepare response
50 data = this.head + js + this.foot;
51 super.doWrite(data, options, callback);
52 }
53}
54exports.JSONP = JSONP;
Note: See TracBrowser for help on using the repository browser.