Best JavaScript code snippet using cypress
test.js
Source:test.js
1"use strict";2const {before, describe, it} = require("mocha");3const customizeURL = require("incomplete-url");4const {expect} = require("chai");5const minURL = require("./");6const httpOnly = url => url.protocol==="http:" || url.protocol==="https:";7const options = overrides =>8({9 clone: false,10 defaultPorts: {},11 indexFilenames: [],12 plusQueries: false,13 queryNames: [],14 removeAuth: false,15 removeDefaultPort: false,16 removeEmptyHash: false,17 removeEmptyQueries: false,18 removeEmptyQueryNames: false,19 removeEmptyQueryValues: false,20 removeEmptySegmentNames: false,21 removeHash: false,22 removeIndexFilename: false,23 removeQueryNames: false,24 removeQueryOddities: false,25 removeRootTrailingSlash: false,26 removeTrailingSlash: false,27 removeWWW: false,28 sortQueries: false,29 stringify: true, // special30 ...overrides31});32it(`has "careful" options profile publicly available`, () =>33{34 expect( minURL.CAREFUL_PROFILE ).to.be.an("object");35 const originalValue = minURL.CAREFUL_PROFILE;36 expect(() => minURL.CAREFUL_PROFILE.defaultPorts = "changed").to.throw(Error);37 expect(() => minURL.CAREFUL_PROFILE.nonExistent = "new").to.throw(Error);38 expect(minURL.CAREFUL_PROFILE).to.deep.equal(originalValue);39 expect(() => minURL.CAREFUL_PROFILE = "changed").to.throw(Error);40 expect(minURL.CAREFUL_PROFILE).to.equal(originalValue);41});42it(`has "common" options profile publicly available`, () =>43{44 expect( minURL.COMMON_PROFILE ).to.be.an("object");45 const originalValue = minURL.COMMON_PROFILE;46 expect(() => minURL.COMMON_PROFILE.defaultPorts = "changed").to.throw(Error);47 expect(() => minURL.COMMON_PROFILE.nonExistent = "new").to.throw(Error);48 expect(minURL.COMMON_PROFILE).to.deep.equal(originalValue);49 expect(() => minURL.COMMON_PROFILE = "changed").to.throw(Error);50 expect(minURL.COMMON_PROFILE).to.equal(originalValue);51});52it("accepts URL input", () =>53{54 const opts = options();55 const url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?qu ery#hash");56 const url2 = "http://user:pass@www.domain.com:123/dir/file.html?qu%20ery#hash";57 expect( minURL(url1,opts) ).to.equal(url2);58});59it("rejects non-URL input", () =>60{61 const opts = options();62 const url = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";63 expect(() => minURL(url, opts)).to.throw(TypeError);64});65describe("options", () =>66{67 // NOTE :: `options.clone` is tested further down68 it("plusQueries = false", () =>69 {70 const opts = options();71 const url1 = "http://user:pass@www.domain.com:123/?va%20+r1=%20+dir&var2=text#hash";72 const url2 = new URL(url1);73 expect( minURL(url2,opts) ).to.equal(url1);74 });75 it("plusQueries = true", () =>76 {77 const opts = options({ plusQueries:true });78 let url1,url2;79 url1 = new URL("http://user:pass@www.domain.com:123/dir%20name/file.html?va%20r1=%20+dir&var2=text#hash");80 url2 = "http://user:pass@www.domain.com:123/dir%20name/file.html?va+r1=++dir&var2=text#hash";81 expect( minURL(url1,opts) ).to.equal(url2);82 url1 = "http://user:pass@www.domain.com:123/dir%20name/file.html#hash";83 url2 = new URL(url1);84 expect( minURL(url2,opts) ).to.equal(url1);85 url1 = new URL("other://user:pass@www.domain.com:123/dir%20name/file.html?va%20r1=%20+dir&var2=text#hash");86 url2 = "other://user:pass@www.domain.com:123/dir%20name/file.html?va+r1=++dir&var2=text#hash";87 expect( minURL(url1,opts) ).to.equal(url2);88 });89 it("plusQueries = function", () =>90 {91 const opts = options({ plusQueries:httpOnly });92 let url1,url2;93 url1 = new URL("http://user:pass@www.domain.com:123/dir%20name/file.html?va%20r1=%20+dir&var2=text#hash");94 url2 = "http://user:pass@www.domain.com:123/dir%20name/file.html?va+r1=++dir&var2=text#hash";95 expect( minURL(url1,opts) ).to.equal(url2);96 url1 = "http://user:pass@www.domain.com:123/dir%20name/file.html#hash";97 url2 = new URL(url1);98 expect( minURL(url2,opts) ).to.equal(url1);99 url1 = "other://user:pass@www.domain.com:123/dir%20name/file.html?va%20r1=%20+dir&var2=text#hash";100 url2 = new URL(url1);101 expect( minURL(url2,opts) ).to.equal(url1);102 });103 it("removeAuth = false", () =>104 {105 const opts = options();106 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";107 const url2 = new URL(url1);108 expect( minURL(url2,opts) ).to.equal(url1);109 });110 it("removeAuth = true", () =>111 {112 const opts = options({ removeAuth:true });113 let url1,url2;114 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");115 url2 = "http://www.domain.com:123/dir/file.html?query#hash";116 expect( minURL(url1,opts) ).to.equal(url2);117 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?query#hash");118 url2 = "other://www.domain.com:123/dir/file.html?query#hash";119 expect( minURL(url1,opts) ).to.equal(url2);120 });121 it("removeAuth = function", () =>122 {123 const opts = options({ removeAuth:httpOnly });124 let url1,url2;125 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");126 url2 = "http://www.domain.com:123/dir/file.html?query#hash";127 expect( minURL(url1,opts) ).to.equal(url2);128 url1 = "other://user:pass@www.domain.com:123/dir/file.html?query#hash";129 url2 = new URL(url1);130 expect( minURL(url2,opts) ).to.equal(url1);131 });132 it("removeDefaultPort = false", () =>133 {134 const opts = options({ defaultPorts:{ "http:":1234 } });135 const url1 = "http://user:pass@www.domain.com:1234/dir/file.html?query#hash";136 const url2 = new URL(url1);137 expect( minURL(url2,opts) ).to.equal(url1);138 });139 it("removeDefaultPort = true", () =>140 {141 const opts = options({ removeDefaultPort:true, defaultPorts:{ "http:":1234 } });142 let url1,url2;143 url1 = new URL("http://user:pass@www.domain.com:1234/dir/file.html?query#hash");144 url2 = "http://user:pass@www.domain.com/dir/file.html?query#hash";145 expect( minURL(url1,opts) ).to.equal(url2);146 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";147 url2 = new URL(url1);148 expect( minURL(url2,opts) ).to.equal(url1);149 url1 = "other://user:pass@www.domain.com:1234/dir/file.html?query#hash";150 url2 = new URL(url1);151 expect( minURL(url2,opts) ).to.equal(url1);152 });153 it("removeDefaultPort = function", () =>154 {155 const opts = options({ removeDefaultPort:httpOnly, defaultPorts:{ "http:":1234, "other:":1234 } });156 let url1,url2;157 url1 = new URL("http://user:pass@www.domain.com:1234/dir/file.html?query#hash");158 url2 = "http://user:pass@www.domain.com/dir/file.html?query#hash";159 expect( minURL(url1,opts) ).to.equal(url2);160 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";161 url2 = new URL(url1);162 expect( minURL(url2,opts) ).to.equal(url1);163 url1 = "other://user:pass@www.domain.com:1234/dir/file.html?query#hash";164 url2 = new URL(url1);165 expect( minURL(url2,opts) ).to.equal(url1);166 });167 it("removeEmptyHash = false", () =>168 {169 const opts = options();170 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#";171 const url2 = new URL(url1);172 expect( minURL(url2,opts) ).to.equal(url1);173 });174 it("removeEmptyHash = true", () =>175 {176 const opts = options({ removeEmptyHash:true });177 let url1,url2;178 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#");179 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query";180 expect( minURL(url1,opts) ).to.equal(url2);181 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";182 url2 = new URL(url1);183 expect( minURL(url2,opts) ).to.equal(url1);184 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query";185 url2 = new URL(url1);186 expect( minURL(url2,opts) ).to.equal(url1);187 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?query#");188 url2 = "other://user:pass@www.domain.com:123/dir/file.html?query";189 expect( minURL(url1,opts) ).to.equal(url2);190 });191 it("removeEmptyHash = function", () =>192 {193 const opts = options({ removeEmptyHash:httpOnly });194 let url1,url2;195 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#");196 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query";197 expect( minURL(url1,opts) ).to.equal(url2);198 url1 = "other://user:pass@www.domain.com:123/dir/file.html?query#";199 url2 = new URL(url1);200 expect( minURL(url2,opts) ).to.equal(url1);201 });202 it("removeEmptyQueries = false", () =>203 {204 const opts = options();205 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?=#hash";206 const url2 = new URL(url1);207 expect( minURL(url2,opts) ).to.equal(url1);208 });209 it("removeEmptyQueries = true", () =>210 {211 const opts = options({ removeEmptyQueries:true });212 let url1,url2;213 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var=#hash";214 url2 = new URL(url1);215 expect( minURL(url2,opts) ).to.equal(url1);216 url1 = "http://user:pass@www.domain.com:123/dir/file.html?=value#hash";217 url2 = new URL(url1);218 expect( minURL(url2,opts) ).to.equal(url1);219 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?=#hash");220 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";221 expect( minURL(url1,opts) ).to.equal(url2);222 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&var2=#hash";223 url2 = new URL(url1);224 expect( minURL(url2,opts) ).to.equal(url1);225 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&=value#hash";226 url2 = new URL(url1);227 expect( minURL(url2,opts) ).to.equal(url1);228 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value&=#hash");229 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value#hash";230 expect( minURL(url1,opts) ).to.equal(url2);231 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var=&var=value&var=#hash";232 url2 = new URL(url1);233 expect( minURL(url2,opts) ).to.equal(url1);234 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");235 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var=&=value#hash";236 expect( minURL(url1,opts) ).to.equal(url2);237 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");238 url2 = "other://user:pass@www.domain.com:123/dir/file.html?var=&=value#hash";239 expect( minURL(url1,opts) ).to.equal(url2);240 });241 it("removeEmptyQueries = function", () =>242 {243 const opts = options({ removeEmptyQueries:httpOnly });244 let url1,url2;245 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?=&=#hash");246 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";247 expect( minURL(url1,opts) ).to.equal(url2);248 url1 = "other://user:pass@www.domain.com:123/dir/file.html?=&=#hash";249 url2 = new URL(url1);250 expect( minURL(url2,opts) ).to.equal(url1);251 });252 it("removeEmptyQueryNames = false", () =>253 {254 const opts = options();255 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?=value#hash";256 const url2 = new URL(url1);257 expect( minURL(url2,opts) ).to.equal(url1);258 });259 it("removeEmptyQueryNames = true", () =>260 {261 const opts = options({ removeEmptyQueryNames:true });262 let url1,url2;263 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var=#hash";264 url2 = new URL(url1);265 expect( minURL(url2,opts) ).to.equal(url1);266 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?=value#hash");267 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";268 expect( minURL(url1,opts) ).to.equal(url2);269 url1 = "http://user:pass@www.domain.com:123/dir/file.html?=#hash";270 url2 = new URL(url1);271 expect( minURL(url2,opts) ).to.equal(url1);272 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&var2=#hash";273 url2 = new URL(url1);274 expect( minURL(url2,opts) ).to.equal(url1);275 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value&=value#hash");276 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value#hash";277 expect( minURL(url1,opts) ).to.equal(url2);278 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&=#hash";279 url2 = new URL(url1);280 expect( minURL(url2,opts) ).to.equal(url1);281 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var=&var=value&var=#hash";282 url2 = new URL(url1);283 expect( minURL(url2,opts) ).to.equal(url1);284 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");285 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var=&=#hash";286 expect( minURL(url1,opts) ).to.equal(url2);287 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");288 url2 = "other://user:pass@www.domain.com:123/dir/file.html?var=&=#hash";289 expect( minURL(url1,opts) ).to.equal(url2);290 });291 it("removeEmptyQueryNames = function", () =>292 {293 const opts = options({ removeEmptyQueryNames:httpOnly });294 let url1,url2;295 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?=value#hash");296 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";297 expect( minURL(url1,opts) ).to.equal(url2);298 url1 = "other://user:pass@www.domain.com:123/dir/file.html?=value#hash";299 url2 = new URL(url1);300 expect( minURL(url2,opts) ).to.equal(url1);301 });302 it("removeEmptyQueryValues = false", () =>303 {304 const opts = options();305 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?var=#hash";306 const url2 = new URL(url1);307 expect( minURL(url2,opts) ).to.equal(url1);308 });309 it("removeEmptyQueryValues = true", () =>310 {311 const opts = options({ removeEmptyQueryValues:true });312 let url1,url2;313 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=#hash");314 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";315 expect( minURL(url1,opts) ).to.equal(url2);316 url1 = "http://user:pass@www.domain.com:123/dir/file.html?=value#hash";317 url2 = new URL(url1);318 expect( minURL(url2,opts) ).to.equal(url1);319 url1 = "http://user:pass@www.domain.com:123/dir/file.html?=#hash";320 url2 = new URL(url1);321 expect( minURL(url2,opts) ).to.equal(url1);322 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value&var2=#hash");323 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value#hash";324 expect( minURL(url1,opts) ).to.equal(url2);325 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&=value#hash";326 url2 = new URL(url1);327 expect( minURL(url2,opts) ).to.equal(url1);328 url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value&=#hash";329 url2 = new URL(url1);330 expect( minURL(url2,opts) ).to.equal(url1);331 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=&var=value&var=#hash");332 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var=value#hash";333 expect( minURL(url1,opts) ).to.equal(url2);334 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");335 url2 = "http://user:pass@www.domain.com:123/dir/file.html?=value&=#hash";336 expect( minURL(url1,opts) ).to.equal(url2);337 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?var=&=value&=#hash");338 url2 = "other://user:pass@www.domain.com:123/dir/file.html?=value&=#hash";339 expect( minURL(url1,opts) ).to.equal(url2);340 });341 it("removeEmptyQueryValues = function", () =>342 {343 const opts = options({ removeEmptyQueryValues:httpOnly });344 let url1,url2;345 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var=#hash");346 url2 = "http://user:pass@www.domain.com:123/dir/file.html#hash";347 expect( minURL(url1,opts) ).to.equal(url2);348 url1 = "other://user:pass@www.domain.com:123/dir/file.html?var=#hash";349 url2 = new URL(url1);350 expect( minURL(url2,opts) ).to.equal(url1);351 });352 it("removeEmptySegmentNames = false", () =>353 {354 const opts = options();355 const url1 = "http://user:pass@www.domain.com:123/dir//file.html?query#hash";356 const url2 = new URL(url1);357 expect( minURL(url2,opts) ).to.equal(url1);358 });359 it("removeEmptySegmentNames = true", () =>360 {361 const opts = options({ removeEmptySegmentNames:true });362 let url1,url2;363 url1 = new URL("http://user:pass@www.domain.com:123/dir//file.html?query#hash");364 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";365 expect( minURL(url1,opts) ).to.equal(url2);366 url1 = new URL("http://user:pass@www.domain.com:123/dir///file.html?query#hash");367 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";368 expect( minURL(url1,opts) ).to.equal(url2);369 url1 = new URL("other://user:pass@www.domain.com:123/dir//file.html?query#hash");370 url2 = "other://user:pass@www.domain.com:123/dir/file.html?query#hash";371 expect( minURL(url1,opts) ).to.equal(url2);372 });373 it("removeEmptySegmentNames = function", () =>374 {375 const opts = options({ removeEmptySegmentNames:httpOnly });376 let url1,url2;377 url1 = new URL("http://user:pass@www.domain.com:123/dir//file.html?query#hash");378 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";379 expect( minURL(url1,opts) ).to.equal(url2);380 url1 = new URL("http://user:pass@www.domain.com:123/dir///file.html?query#hash");381 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";382 expect( minURL(url1,opts) ).to.equal(url2);383 url1 = "other://user:pass@www.domain.com:123/dir//file.html?query#hash";384 url2 = new URL(url1);385 expect( minURL(url2,opts) ).to.equal(url1);386 });387 it("removeHash = false", () =>388 {389 const opts = options();390 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";391 const url2 = new URL(url1);392 expect( minURL(url2,opts) ).to.equal(url1);393 });394 it("removeHash = true", () =>395 {396 const opts = options({ removeHash:true });397 let url1,url2;398 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");399 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query";400 expect( minURL(url1,opts) ).to.equal(url2);401 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#");402 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query";403 expect( minURL(url1,opts) ).to.equal(url2);404 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query";405 url2 = new URL(url1);406 expect( minURL(url2,opts) ).to.equal(url1);407 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?query#hash");408 url2 = "other://user:pass@www.domain.com:123/dir/file.html?query";409 expect( minURL(url1,opts) ).to.equal(url2);410 });411 it("removeHash = function", () =>412 {413 const opts = options({ removeHash:httpOnly });414 let url1,url2;415 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");416 url2 = "http://user:pass@www.domain.com:123/dir/file.html?query";417 expect( minURL(url1,opts) ).to.equal(url2);418 url1 = "other://user:pass@www.domain.com:123/dir/file.html?query#hash";419 url2 = new URL(url1);420 expect( minURL(url2,opts) ).to.equal(url1);421 });422 it("removeIndexFilename = false", () =>423 {424 const opts = options({ indexFilenames:["other.html"] });425 const url1 = "http://user:pass@www.domain.com:123/dir/other.html?query#hash";426 const url2 = new URL(url1);427 expect( minURL(url2,opts) ).to.equal(url1);428 });429 it("removeIndexFilename = true", () =>430 {431 let opts = options({ removeIndexFilename:true, indexFilenames:["other.html"] });432 let url1,url2;433 url1 = new URL("http://user:pass@www.domain.com:123/other.html");434 url2 = "http://user:pass@www.domain.com:123/";435 expect( minURL(url1,opts) ).to.equal(url2);436 url1 = new URL("http://user:pass@www.domain.com:123/dir/other.html?query#hash");437 url2 = "http://user:pass@www.domain.com:123/dir/?query#hash";438 expect( minURL(url1,opts) ).to.equal(url2);439 url1 = "http://user:pass@www.domain.com:123/another.html";440 url2 = new URL(url1);441 expect( minURL(url2,opts) ).to.equal(url1);442 url1 = "http://user:pass@www.domain.com:123/dir/another.html?query#hash";443 url2 = new URL(url1);444 expect( minURL(url2,opts) ).to.equal(url1);445 url1 = new URL("other://user:pass@www.domain.com:123/other.html?query#hash");446 url2 = "other://user:pass@www.domain.com:123/?query#hash";447 expect( minURL(url1,opts) ).to.equal(url2);448 opts = options({ removeIndexFilename:true, indexFilenames:[/^another\.[a-z]+$/] });449 url1 = new URL("http://user:pass@www.domain.com:123/another.html");450 url2 = "http://user:pass@www.domain.com:123/";451 expect( minURL(url1,opts) ).to.equal(url2);452 });453 it("removeIndexFilename = function", () =>454 {455 const opts = options({ removeIndexFilename:httpOnly, indexFilenames:["other.html"] });456 let url1,url2;457 url1 = new URL("http://user:pass@www.domain.com:123/other.html?query#hash");458 url2 = "http://user:pass@www.domain.com:123/?query#hash";459 expect( minURL(url1,opts) ).to.equal(url2);460 url1 = "other://user:pass@www.domain.com:123/other.html?query#hash";461 url2 = new URL(url1);462 expect( minURL(url2,opts) ).to.equal(url1);463 });464 it("removeQueryNames = false", () =>465 {466 const opts = options({ queryNames:["query"] });467 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?query=value#hash";468 const url2 = new URL(url1);469 expect( minURL(url2,opts) ).to.equal(url1);470 });471 it("removeQueryNames = true", () =>472 {473 let opts,url1,url2;474 opts = options({ queryNames:["var1"], removeQueryNames:true });475 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var1=value2&var2=value#hash");476 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var2=value#hash";477 expect( minURL(url1,opts) ).to.equal(url2);478 opts = options({ queryNames:[/^var\d+$/], removeQueryNames:true });479 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var1=value2&var2=value&var=value#hash");480 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var=value#hash";481 expect( minURL(url1,opts) ).to.equal(url2);482 });483 it("removeQueryNames = function", () =>484 {485 const opts = options({ queryNames:["var1"], removeQueryNames:httpOnly });486 let url1,url2;487 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value&var2=value#hash");488 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var2=value#hash";489 expect( minURL(url1,opts) ).to.equal(url2);490 url1 = "other://user:pass@www.domain.com:123/dir/file.html?query#hash";491 url2 = new URL(url1);492 expect( minURL(url2,opts) ).to.equal(url1);493 });494 it("removeQueryOddities = false", () =>495 {496 const opts = options();497 const url1 = "http://user:pass@domain.com/?";498 const url2 = new URL(url1);499 expect( minURL(url2,opts) ).to.equal(url1);500 });501 it("removeQueryOddities = true", () =>502 {503 const opts = options({ removeQueryOddities:true });504 let url1,url2;505 url1 = new URL("http://user:pass@domain.com/?");506 url2 = "http://user:pass@domain.com/";507 expect( minURL(url1,opts) ).to.equal(url2);508 url1 = new URL("http://user:pass@domain.com/?#hash");509 url2 = "http://user:pass@domain.com/#hash";510 expect( minURL(url1,opts) ).to.equal(url2);511 url1 = new URL("http://user:pass@domain.com/?#");512 url2 = "http://user:pass@domain.com/#";513 expect( minURL(url1,opts) ).to.equal(url2);514 url1 = new URL("http://user:pass@domain.com/?var=");515 url2 = "http://user:pass@domain.com/?var";516 expect( minURL(url1,opts) ).to.equal(url2);517 url1 = new URL("http://user:pass@domain.com/?var1=&var2=");518 url2 = "http://user:pass@domain.com/?var1&var2";519 expect( minURL(url1,opts) ).to.equal(url2);520 url1 = "http://user:pass@domain.com/?var&";521 url2 = new URL(url1);522 expect( minURL(url2,opts) ).to.equal(url1);523 url1 = "http://user:pass@domain.com/?var&&";524 url2 = new URL(url1);525 expect( minURL(url2,opts) ).to.equal(url1);526 url1 = "http://user:pass@domain.com/?=";527 url2 = new URL(url1);528 expect( minURL(url2,opts) ).to.equal(url1);529 url1 = "http://user:pass@domain.com/?var&=";530 url2 = new URL(url1);531 expect( minURL(url2,opts) ).to.equal(url1);532 url1 = "http://user:pass@domain.com/??var";533 url2 = new URL(url1);534 expect( minURL(url2,opts) ).to.equal(url1);535 url1 = "http://user:pass@domain.com/?var==value";536 url2 = new URL(url1);537 expect( minURL(url2,opts) ).to.equal(url1);538 url1 = "http://user:pass@domain.com/";539 url2 = new URL(url1);540 expect( minURL(url2,opts) ).to.equal(url1);541 });542 it("removeQueryOddities = function", () =>543 {544 const opts = options({ removeQueryOddities:httpOnly });545 let url1,url2;546 url1 = new URL("http://user:pass@domain.com/?");547 url2 = "http://user:pass@domain.com/";548 expect( minURL(url1,opts) ).to.equal(url2);549 url1 = "other://user:pass@domain.com/?";550 url2 = new URL(url1);551 expect( minURL(url2,opts) ).to.equal(url1);552 });553 it("removeRootTrailingSlash = false", () =>554 {555 const opts = options();556 const url1 = "http://user:pass@www.domain.com:123/";557 const url2 = new URL(url1);558 expect( minURL(url2,opts) ).to.equal(url1);559 });560 it("removeRootTrailingSlash = true", () =>561 {562 const opts = options({ removeRootTrailingSlash:true });563 let url1,url2;564 url1 = new URL("http://user:pass@www.domain.com:123/");565 url2 = "http://user:pass@www.domain.com:123";566 expect( minURL(url1,opts) ).to.equal(url2);567 url1 = "http://user:pass@www.domain.com:123//";568 url2 = new URL(url1);569 expect( minURL(url2,opts) ).to.equal(url1);570 url1 = new URL("http://user:pass@www.domain.com:123/?query#hash");571 url2 = "http://user:pass@www.domain.com:123?query#hash";572 expect( minURL(url1,opts) ).to.equal(url2);573 url1 = "http://user:pass@www.domain.com:123/file.html?query#hash";574 url2 = new URL(url1);575 expect( minURL(url2,opts) ).to.equal(url1);576 url1 = "http://user:pass@www.domain.com:123/dir/?query#hash";577 url2 = new URL(url1);578 expect( minURL(url2,opts) ).to.equal(url1);579 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";580 url2 = new URL(url1);581 expect( minURL(url2,opts) ).to.equal(url1);582 url1 = "http://user:pass@www.domain.com:123//?query#hash";583 url2 = new URL(url1);584 expect( minURL(url2,opts) ).to.equal(url1);585 url1 = "http://user:pass@www.domain.com/www.domain.com/?query#hash";586 url2 = new URL(url1);587 expect( minURL(url2,opts) ).to.equal(url1);588 url1 = "http://user:pass@www.á¯á¯á¯.ExAmPlE/?query#hash";589 url2 = new URL(url1);590 expect( minURL(url2,opts) ).to.equal("http://user:pass@www.xn--brdaa.example?query#hash");591 url1 = new URL("other://user:pass@www.domain.com:123/?query#hash");592 url2 = "other://user:pass@www.domain.com:123?query#hash";593 expect( minURL(url1,opts) ).to.equal(url2);594 url1 = new URL("file:\\\\\\C:\\");595 url2 = "file:///C:/";596 expect( minURL(url1,opts) ).to.equal(url2);597 url1 = "file:///C:/dir/?query#hash";598 url2 = new URL(url1);599 expect( minURL(url2,opts) ).to.equal(url1);600 url1 = "file:///C:/dir1/dir2/?query#hash";601 url2 = new URL(url1);602 expect( minURL(url2,opts) ).to.equal(url1);603 url1 = "file:///dir/?query#hash";604 url2 = new URL(url1);605 expect( minURL(url2,opts) ).to.equal(url1);606 url1 = "file:///dir1/dir2/?query#hash";607 url2 = new URL(url1);608 expect( minURL(url2,opts) ).to.equal(url1);609 url1 = new URL("file:///");610 url2 = "file://";611 expect( minURL(url1,opts) ).to.equal(url2);612 });613 it("removeRootTrailingSlash = function", () =>614 {615 const opts = options({ removeRootTrailingSlash:httpOnly });616 let url1,url2;617 url1 = new URL("http://user:pass@www.domain.com:123/?query#hash");618 url2 = "http://user:pass@www.domain.com:123?query#hash";619 expect( minURL(url1,opts) ).to.equal(url2);620 url1 = "other://user:pass@www.domain.com:123/?query#hash";621 url2 = new URL(url1);622 expect( minURL(url2,opts) ).to.equal(url1);623 });624 it("removeTrailingSlash = false", () =>625 {626 const opts = options();627 const url1 = "http://user:pass@www.domain.com:123/";628 const url2 = new URL(url1);629 expect( minURL(url2,opts) ).to.equal(url1);630 });631 it("removeTrailingSlash = true", () =>632 {633 const opts = options({ removeTrailingSlash:true });634 let url1,url2;635 url1 = new URL("http://user:pass@www.domain.com:123/");636 url2 = "http://user:pass@www.domain.com:123";637 expect( minURL(url1,opts) ).to.equal(url2);638 url1 = "http://user:pass@www.domain.com:123//";639 url2 = new URL(url1);640 expect( minURL(url2,opts) ).to.equal(url1);641 url1 = new URL("http://user:pass@www.domain.com:123/?query#hash");642 url2 = "http://user:pass@www.domain.com:123?query#hash";643 expect( minURL(url1,opts) ).to.equal(url2);644 url1 = "http://user:pass@www.domain.com:123/file.html?query#hash";645 url2 = new URL(url1);646 expect( minURL(url2,opts) ).to.equal(url1);647 url1 = new URL("http://user:pass@www.domain.com:123/dir/?query#hash");648 url2 = "http://user:pass@www.domain.com:123/dir?query#hash";649 expect( minURL(url1,opts) ).to.equal(url2);650 url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";651 url2 = new URL(url1);652 expect( minURL(url2,opts) ).to.equal(url1);653 url1 = "http://user:pass@www.domain.com:123/dir//?query#hash";654 url2 = new URL(url1);655 expect( minURL(url2,opts) ).to.equal(url1);656 url1 = new URL("http://user:pass@www.domain.com/www.domain.com/?query#hash");657 url2 = "http://user:pass@www.domain.com/www.domain.com?query#hash";658 expect( minURL(url1,opts) ).to.equal(url2);659 url1 = "http://user:pass@www.á¯á¯á¯.ExAmPlE/?query#hash";660 url2 = new URL(url1);661 expect( minURL(url2,opts) ).to.equal("http://user:pass@www.xn--brdaa.example?query#hash");662 url1 = new URL("other://user:pass@www.domain.com:123/dir/?query#hash");663 url2 = "other://user:pass@www.domain.com:123/dir?query#hash";664 expect( minURL(url1,opts) ).to.equal(url2);665 url1 = new URL("file:\\\\\\C:\\");666 url2 = "file:///C:";667 expect( minURL(url1,opts) ).to.equal(url2);668 url1 = new URL("file:///C:/dir/?query#hash");669 url2 = "file:///C:/dir?query#hash";670 expect( minURL(url1,opts) ).to.equal(url2);671 url1 = new URL("file:///C:/dir1/dir2/?query#hash");672 url2 = "file:///C:/dir1/dir2?query#hash";673 expect( minURL(url1,opts) ).to.equal(url2);674 url1 = new URL("file:///dir/?query#hash");675 url2 = "file:///dir?query#hash";676 expect( minURL(url1,opts) ).to.equal(url2);677 url1 = new URL("file:///dir1/dir2/?query#hash");678 url2 = "file:///dir1/dir2?query#hash";679 expect( minURL(url1,opts) ).to.equal(url2);680 url1 = new URL("file:///");681 url2 = "file://";682 expect( minURL(url1,opts) ).to.equal(url2);683 });684 it("removeTrailingSlash = function", () =>685 {686 const opts = options({ removeTrailingSlash:httpOnly });687 let url1,url2;688 url1 = new URL("http://user:pass@www.domain.com/dir/?query#hash");689 url2 = "http://user:pass@www.domain.com/dir?query#hash";690 expect( minURL(url1,opts) ).to.equal(url2);691 url1 = "other://user:pass@www.domain.com/dir/?query#hash";692 url2 = new URL(url1);693 expect( minURL(url2,opts) ).to.equal(url1);694 });695 it("removeWWW = false", () =>696 {697 const opts = options();698 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?query#hash";699 const url2 = new URL(url1);700 expect( minURL(url2,opts) ).to.equal(url1);701 });702 it("removeWWW = true", () =>703 {704 const opts = options({ removeWWW:true });705 let url1,url2;706 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");707 url2 = "http://user:pass@domain.com:123/dir/file.html?query#hash";708 expect( minURL(url1,opts) ).to.equal(url2);709 url1 = "http://user:pass@www.domain:123/dir/file.html?query#hash";710 url2 = new URL(url1);711 expect( minURL(url2,opts) ).to.equal(url1);712 url1 = "http://user:pass@www.á¯á¯á¯.ExAmPlE.com:123/dir/file.html?query#hash";713 url2 = new URL(url1);714 expect( minURL(url2,opts) ).to.equal("http://user:pass@xn--brdaa.example.com:123/dir/file.html?query#hash");715 url1 = "http://user:pass@www2.domain.com:123/dir/file.html?query#hash";716 url2 = new URL(url1);717 expect( minURL(url2,opts) ).to.equal(url1);718 url1 = "file:///www.domain.com/";719 url2 = new URL(url1);720 expect( minURL(url2,opts) ).to.equal(url1);721 url1 = new URL("other://user:pass@www.domain.com:123/dir/file.html?query#hash");722 url2 = "other://user:pass@domain.com:123/dir/file.html?query#hash";723 expect( minURL(url1,opts) ).to.equal(url2);724 });725 it("removeWWW = function", () =>726 {727 const opts = options({ removeWWW:httpOnly });728 let url1,url2;729 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?query#hash");730 url2 = "http://user:pass@domain.com:123/dir/file.html?query#hash";731 expect( minURL(url1,opts) ).to.equal(url2);732 url1 = "http://user:pass@www.domain:123/dir/file.html?query#hash";733 url2 = new URL(url1);734 expect( minURL(url2,opts) ).to.equal(url1);735 url1 = "other://user:pass@www.domain.com:123/dir/file.html?query#hash";736 url2 = new URL(url1);737 expect( minURL(url2,opts) ).to.equal(url1);738 });739 it("sortQueries = false", () =>740 {741 const opts = options();742 const url1 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var2=value&var1=value2#hash";743 const url2 = new URL(url1);744 expect( minURL(url2,opts) ).to.equal(url1);745 });746 it("sortQueries = true", () =>747 {748 const opts = options({ sortQueries:true });749 const url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var2=value&var1=value2#hash");750 const url2 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var1=value2&var2=value#hash";751 expect( minURL(url1,opts) ).to.equal(url2);752 });753 it("sortQueries = function", () =>754 {755 const opts = options({ sortQueries:httpOnly });756 let url1,url2;757 url1 = new URL("http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var2=value&var1=value2#hash");758 url2 = "http://user:pass@www.domain.com:123/dir/file.html?var1=value1&var1=value2&var2=value#hash";759 expect( minURL(url1,opts) ).to.equal(url2);760 url1 = "other://user:pass@www.domain.com:123/dir/file.html?var1=value1&var2=value&var1=value2#hash";761 url2 = new URL(url1);762 expect( minURL(url2,opts) ).to.equal(url1);763 });764 it("stringify = false", () =>765 {766 const opts = options({ removeRootTrailingSlash:true, removeTrailingSlash:true, stringify:false });767 let url1,url2;768 url1 = new URL("http://user:pass@www.domain.com:123/");769 url2 = minURL(new URL(url1), opts);770 expect(url2).to.be.an.instanceOf(URL);771 expect(url2).to.deep.equal(url1);772 url1 = new URL("http://user:pass@www.domain.com:123/dir/");773 url2 = minURL(new URL(url1), opts);774 expect(url2).to.be.an.instanceOf(URL);775 expect(url2).to.deep.equal(url1);776 });777 it("stringify = true", () =>778 {779 const opts = options({ removeRootTrailingSlash:true, removeTrailingSlash:true });780 let url1,url2;781 url1 = new URL("http://user:pass@www.domain.com:123/");782 url2 = "http://user:pass@www.domain.com:123";783 expect( minURL(url1,opts) ).to.equal(url2);784 url1 = new URL("http://user:pass@www.domain.com:123/dir/");785 url2 = "http://user:pass@www.domain.com:123/dir";786 expect( minURL(url1,opts) ).to.equal(url2);787 });788 it("clone = false, removeWWW = true, stringify = false", () =>789 {790 const opts = options({ removeWWW:true, stringify:false });791 const url = new URL("http://user:pass@www.domain.com/");792 const result = minURL(url, opts);793 expect(result).to.equal(url);794 expect(result.href).to.equal("http://user:pass@domain.com/");795 });796 it("clone = true, removeWWW = true, stringify = false", () =>797 {798 const opts = options({ clone:true, removeWWW:true, stringify:false });799 const url = new URL("http://user:pass@www.domain.com/");800 const result = minURL(url, opts);801 expect(result).to.not.equal(url);802 expect(result.href).to.equal("http://user:pass@domain.com/");803 });804 describe("in careful profile", () =>805 {806 it("works", () =>807 {808 const opts = minURL.CAREFUL_PROFILE;809 let url1,url2;810 // plusQueries811 // removeDefaultPort812 // removeEmptyHash813 // ~~removeEmptyQueries~~814 // ~~removeIndexFilename~~815 // removeQueryOddities816 // removeRootTrailingSlash817 // ~~removeTrailingSlash~~818 // ~~removeWWW~~819 // ~~sortQueries~~820 url1 = new URL("http://user:pass@www.domain.com:80/?va%20r2=%20dir&var1=text&var3=#");821 url2 = "http://user:pass@www.domain.com?va+r2=+dir&var1=text&var3";822 expect( minURL(url1,opts) ).to.equal(url2);823 url1 = new URL("https://user:pass@www.domain.com:443/?va%20r2=%20dir&var1=text&var3=#");824 url2 = "https://user:pass@www.domain.com?va+r2=+dir&var1=text&var3";825 expect( minURL(url1,opts) ).to.equal(url2);826 // plusQueries827 // removeDefaultPort828 // removeEmptyHash829 // ~~removeEmptyQueries~~830 // ~~removeIndexFilename~~831 // removeQueryOddities832 // ~~removeRootTrailingSlash~~833 // ~~removeTrailingSlash~~834 // ~~removeWWW~~835 // ~~sortQueries~~836 url1 = new URL("http://user:pass@www.domain.com:80/dir/?va%20r2=%20dir&var1=text&var3=#");837 url2 = "http://user:pass@www.domain.com/dir/?va+r2=+dir&var1=text&var3";838 expect( minURL(url1,opts) ).to.equal(url2);839 url1 = new URL("https://user:pass@www.domain.com:443/dir/?va%20r2=%20dir&var1=text&var3=#");840 url2 = "https://user:pass@www.domain.com/dir/?va+r2=+dir&var1=text&var3";841 expect( minURL(url1,opts) ).to.equal(url2);842 // plusQueries843 // removeDefaultPort844 // removeEmptyHash845 // ~~removeEmptyQueries~~846 // ~~removeIndexFilename~~847 // removeQueryOddities848 // ~~removeRootTrailingSlash~~849 // ~~removeTrailingSlash~~850 // ~~removeWWW~~851 // ~~sortQueries~~852 url1 = new URL("http://user:pass@www.domain.com:80/dir/index.html?va%20r2=%20dir&var1=text&var3=#");853 url2 = "http://user:pass@www.domain.com/dir/index.html?va+r2=+dir&var1=text&var3";854 expect( minURL(url1,opts) ).to.equal(url2);855 url1 = new URL("https://user:pass@www.domain.com:443/dir/index.html?va%20r2=%20dir&var1=text&var3=#");856 url2 = "https://user:pass@www.domain.com/dir/index.html?va+r2=+dir&var1=text&var3";857 expect( minURL(url1,opts) ).to.equal(url2);858 // plusQueries859 // removeDefaultPort860 // removeEmptyHash861 // ~~removeEmptyQueries~~862 // ~~removeIndexFilename~~863 // removeQueryOddities864 // ~~removeRootTrailingSlash~~865 // ~~removeTrailingSlash~~866 // ~~removeWWW~~867 // ~~sortQueries~~868 url1 = new URL("ftps://user@www.domain.com:990/dir/index.html?var2=hello%20world&var1=#");869 url2 = "ftps://user@www.domain.com/dir/index.html?var2=hello+world&var1";870 expect( minURL(url1,opts) ).to.equal(url2);871 url1 = new URL("git://user@www.domain.com:9418/index.html?var2=hello%20world&var1=#");872 url2 = "git://user@www.domain.com/index.html?var2=hello+world&var1";873 expect( minURL(url1,opts) ).to.equal(url2);874 url1 = new URL("scp://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");875 url2 = "scp://user@www.domain.com/dir/index.html?var2=hello+world&var1";876 expect( minURL(url1,opts) ).to.equal(url2);877 url1 = new URL("sftp://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");878 url2 = "sftp://user@www.domain.com/dir/index.html?var2=hello+world&var1";879 expect( minURL(url1,opts) ).to.equal(url2);880 url1 = new URL("ssh://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");881 url2 = "ssh://user@www.domain.com/dir/index.html?var2=hello+world&var1";882 expect( minURL(url1,opts) ).to.equal(url2);883 // plusQueries884 // ~~removeDefaultPort~~885 // removeEmptyHash886 // removeEmptyQueries887 // ~~removeIndexFilename~~888 // removeQueryOddities889 // ~~removeRootTrailingSlash~~890 // ~~removeTrailingSlash~~891 // ~~removeWWW~~892 // sortQueries893 url1 = new URL("mailto:email@www.domain.com:123?subject=hello%20world&cc=user@domain.com&body=&#");894 url2 = "mailto:email@www.domain.com:123?cc=user%40domain.com&subject=hello+world";895 expect( minURL(url1,opts) ).to.equal(url2);896 // ~~plusQueries~~897 // ~~removeDefaultPort~~898 // ~~removeEmptyHash~~899 // ~~removeEmptyQueries~~900 // ~~removeIndexFilename~~901 // removeQueryOddities902 // removeRootTrailingSlash903 // ~~removeTrailingSlash~~904 // ~~removeWWW~~905 // ~~sortQueries~~906 url1 = new URL("other://user:pass@www.domain.com:123/?");907 url2 = "other://user:pass@www.domain.com:123";908 expect( minURL(url1,opts) ).to.equal(url2);909 });910 });911 const commonProfileTests = opts =>912 {913 it("works", () =>914 {915 let url1,url2;916 // plusQueries917 // removeDefaultPort918 // removeEmptyHash919 // ~~removeEmptyQueries~~920 // removeIndexFilename921 // removeQueryOddities922 // removeRootTrailingSlash923 // ~~removeTrailingSlash~~924 // removeWWW925 // ~~sortQueries~~926 url1 = new URL("http://user:pass@www.domain.com:80/index.html?va%20r2=%20dir&var1=text&var3=#");927 url2 = "http://user:pass@domain.com?va+r2=+dir&var1=text&var3";928 expect( minURL(url1,opts) ).to.equal(url2);929 url1 = new URL("https://user:pass@www.domain.com:443/index.html?va%20r2=%20dir&var1=text&var3=#");930 url2 = "https://user:pass@domain.com?va+r2=+dir&var1=text&var3";931 expect( minURL(url1,opts) ).to.equal(url2);932 // plusQueries933 // removeDefaultPort934 // removeEmptyHash935 // ~~removeEmptyQueries~~936 // removeIndexFilename937 // removeQueryOddities938 // ~~removeRootTrailingSlash~~939 // ~~removeTrailingSlash~~940 // removeWWW941 // ~~sortQueries~~942 url1 = new URL("http://user:pass@www.domain.com:80/dir/index.html?va%20r2=%20dir&var1=text&var3=#");943 url2 = "http://user:pass@domain.com/dir/?va+r2=+dir&var1=text&var3";944 expect( minURL(url1,opts) ).to.equal(url2);945 url1 = new URL("https://user:pass@www.domain.com:443/dir/index.html?va%20r2=%20dir&var1=text&var3=#");946 url2 = "https://user:pass@domain.com/dir/?va+r2=+dir&var1=text&var3";947 expect( minURL(url1,opts) ).to.equal(url2);948 // plusQueries949 // removeDefaultPort950 // removeEmptyHash951 // ~~removeEmptyQueries~~952 // ~~removeIndexFilename~~953 // removeQueryOddities954 // ~~removeRootTrailingSlash~~955 // ~~removeTrailingSlash~~956 // ~~removeWWW~~957 // ~~sortQueries~~958 url1 = new URL("ftps://user@www.domain.com:990/dir/index.html?var2=hello%20world&var1=#");959 url2 = "ftps://user@www.domain.com/dir/index.html?var2=hello+world&var1";960 expect( minURL(url1,opts) ).to.equal(url2);961 url1 = new URL("git://user@www.domain.com:9418/index.html?var2=hello%20world&var1=#");962 url2 = "git://user@www.domain.com/index.html?var2=hello+world&var1";963 expect( minURL(url1,opts) ).to.equal(url2);964 url1 = new URL("scp://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");965 url2 = "scp://user@www.domain.com/dir/index.html?var2=hello+world&var1";966 expect( minURL(url1,opts) ).to.equal(url2);967 url1 = new URL("sftp://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");968 url2 = "sftp://user@www.domain.com/dir/index.html?var2=hello+world&var1";969 expect( minURL(url1,opts) ).to.equal(url2);970 url1 = new URL("ssh://user@www.domain.com:22/dir/index.html?var2=hello%20world&var1=#");971 url2 = "ssh://user@www.domain.com/dir/index.html?var2=hello+world&var1";972 expect( minURL(url1,opts) ).to.equal(url2);973 // plusQueries974 // ~~removeDefaultPort~~975 // removeEmptyHash976 // removeEmptyQueries977 // ~~removeIndexFilename~~978 // removeQueryOddities979 // ~~removeRootTrailingSlash~~980 // ~~removeTrailingSlash~~981 // ~~removeWWW~~982 // sortQueries983 url1 = new URL("mailto:email@www.domain.com:123?subject=hello%20world&cc=user@domain.com&body=&#");984 url2 = "mailto:email@www.domain.com:123?cc=user%40domain.com&subject=hello+world";985 expect( minURL(url1,opts) ).to.equal(url2);986 // ~~plusQueries~~987 // ~~removeDefaultPort~~988 // ~~removeEmptyHash~~989 // ~~removeEmptyQueries~~990 // ~~removeIndexFilename~~991 // removeQueryOddities992 // removeRootTrailingSlash993 // ~~removeTrailingSlash~~994 // ~~removeWWW~~995 // ~~sortQueries~~996 url1 = new URL("other://user:pass@www.domain.com:123/?");997 url2 = "other://user:pass@www.domain.com:123";998 expect( minURL(url1,opts) ).to.equal(url2);999 });1000 describe("with URL implementations lacking searchParams", () =>1001 {1002 const opts2 = { ...opts, clone:false }; // avoids using Node's `URL` on >=7.x1003 let IncompleteURL;1004 before(() => IncompleteURL = customizeURL({ urlExclusions:["searchParams"] }).IncompleteURL);1005 it("works", () =>1006 {1007 // plusQueries1008 // ~~removeDefaultPort~~1009 // removeEmptyHash1010 // removeEmptyQueries1011 // ~~removeIndexFilename~~1012 // removeQueryOddities1013 // ~~removeRootTrailingSlash~~1014 // ~~removeTrailingSlash~~1015 // ~~removeWWW~~1016 // sortQueries1017 const url1 = new IncompleteURL("mailto:email@www.domain.com:123?subject=hello%20world&cc=user@domain.com&body=&#");1018 const url2 = "mailto:email@www.domain.com:123?subject=hello+world&cc=user@domain.com&body&";1019 expect( minURL(url1,opts2) ).to.equal(url2);1020 });1021 });1022 describe("with URL implementations lacking searchParams::sort", () =>1023 {1024 const opts2 = { ...opts, clone:false }; // avoids using Node's `URL` on >=7.x1025 let IncompleteURL;1026 before(() => IncompleteURL = customizeURL({ paramsExclusions:["sort"] }).IncompleteURL);1027 it("works", () =>1028 {1029 // plusQueries1030 // ~~removeDefaultPort~~1031 // removeEmptyHash1032 // removeEmptyQueries1033 // ~~removeIndexFilename~~1034 // removeQueryOddities1035 // ~~removeRootTrailingSlash~~1036 // ~~removeTrailingSlash~~1037 // ~~removeWWW~~1038 // sortQueries1039 const url1 = new IncompleteURL("mailto:email@www.domain.com:123?subject=hello%20world&cc=user@domain.com&body=&#");1040 const url2 = "mailto:email@www.domain.com:123?subject=hello+world&cc=user%40domain.com";1041 expect( minURL(url1,opts2) ).to.equal(url2);1042 });1043 });1044 }1045 describe("in common profile", () =>1046 {1047 commonProfileTests(minURL.COMMON_PROFILE);1048 });1049 describe("in default profile", () =>1050 {1051 commonProfileTests();1052 });...
performance.js
Source:performance.js
1var __csm_PF=function(){var b=null,c=true,d=false;this._csm_CrossDomainChecker=function(f,h){var b="/",a=this;a.inited=d;a.pageProtocol="";a.pageDomain="";a.documentDomain="";a.documentDomainLength=-1;a.RemoveDefaultPort=function(a){var b=a.lastIndexOf(":80");return-1!=b?a.substr(0,b):a};var e=f.indexOf("://");if(-1!=e){a.pageProtocol=f.substr(0,e);var g=f.indexOf(b,e+3);if(-1!=g)g==f.length-1;a.pageDomain=a.RemoveDefaultPort(f.substr(e+3,g-e-3)).toLowerCase();a.documentDomain=a.RemoveDefaultPort(h).toLowerCase();a.documentDomainLength=a.documentDomain.length;if(0==a.documentDomainLength)a.documentDomainLength=-1;a.inited=c}a.CompareURLForCrossDomain=function(a){var g=this;if(d==g.inited)return d;var e=a.indexOf("://");if(-1==e)if(a.charAt(0)!=b||a.charAt(1)!=b)return c;if(a.charAt(0)!=b||a.charAt(1)!=b){var h=a.substr(0,e);if(h!=g.pageProtocol)return d}var f=a.indexOf(b,e+3);f=-1!=f?f:a.length-1;var i=g.RemoveDefaultPort(a.substr(e+3,f-e-3)).toLowerCase();return i==g.pageDomain?c:d}};var a={CrossDomainChecker:new this._csm_CrossDomainChecker(document.URL,document.domain),AjaxRequestObject:new __csm_st.AjaxRequestObject,scriptsCollectingLimit:__csm_st.Limits.GetScriptsCountLimit(),cssCollectingLimit:__csm_st.Limits.GetCssCountLimit(),htcCollectingLimit:__csm_st.Limits.GetHtcCountLimit(),cssRulesCollectingLimit:__csm_st.Limits.GetCssRulesCountLimit(),Codes:{_ok:"OK",_none:"none",_invalidContent:"invalidContent",_XDomain:"XDomain",_unknownError:"UnknownError"},NeedToIncludeContentItem:function(f,e,b){var a=d;if(e)if(b){if(f>=__csm_pa.D1.A27)a=c}else a=c;return a},GetSizeBySrc:function(g,j){var e={code:a.Codes._unknownError,_size:-1};if(a.CrossDomainChecker.CompareURLForCrossDomain(g)){var f=a.AjaxRequestObject.Instance();if(f!=b)try{while(g.indexOf('"')>-1)g=g.replace('"',"");f.open("GET",g,d);f.setRequestHeader("Connection","Keep-Alive");f.send(b);var m=f.status;if(200==m){for(var l=f.getResponseHeader("Content-Type").toLowerCase(),k=d,n=j.length,i=0;i<n;i++)if(l.indexOf(j[i])>-1){k=c;break}if(k){var h=f.getResponseHeader("Content-length");if(h!=b&&h!="")e._size=parseInt(h);else e._size=f.responseText.length;e.code=a.Codes._ok}else{e.code=a.Codes._invalidContent;e._size=-1}}}catch(o){e.code=a.Codes._unknownError;e._errorMessage=o.message;e._size=-1}}else{e.code=a.Codes._XDomain;e._size=-1}if(isNaN(e._size))e._size=-1;return e},GetImageLoadingTime:function(h,c){var g=+new Date,i=g-c,b={startTime:-1,endTime:-1,loadingTime:-1,isCached:-1};if(typeof __csm_pr!=__csm_st.Constants.udf&&typeof __csm_pr.ContentManager!=__csm_st.Constants.udf){var a=__csm_pr.ContentManager.imagesManager[h];if(a){var f=typeof a.s!=__csm_st.Constants.udf,e=typeof a.e!=__csm_st.Constants.udf;if(f&&e&&a.e>=a.s){var d=__csm_st.ExcludedFunctions.GetBlocksDuration(c,a.s);b.startTime=a.s-c-d;b.endTime=a.e-c-d;b.loadingTime=a.e-a.s}else if(!f&&e){var d=__csm_st.ExcludedFunctions.GetBlocksDuration(c,a.e);b.endTime=a.e-c-d;b.loadingTime=-1}else if(f&&!e){var d=__csm_st.ExcludedFunctions.GetBlocksDuration(c,a.s);b.startTime=a.s-c-d;b.loadingTime=-1}else{b.loadingTime=-1;b.startTime=-1}}}return b},GetImages:function(){return document.images},GetImageSize:function(e){var a=-1,b=10,c=d;while(b>0&&!c){a=e.fileSize;c=a>-1;b--}a=parseInt(a);return a},GetImagesInfo:function(){var e={totalSize:0,totalCount:0,domTotalCount:0,imagesInfo:[],beforeDomCount:0,beforeDomSize:0},k=a.GetImages(),o=k.length;e.domTotalCount=o;var r=__csm_pa.B21.getTime(),n=__csm_st.ExcludedFunctions.GetReducedIntervalTime(__csm_st.A70.t7,r);if(o>0){var s=d;if(typeof k[0].fileSize!=__csm_st.Constants.udf)s=c;for(var v=[],u=0,w=d,p=d,m=d,x=Math.min(o,__csm_st.A70.imagesCollectingLimit),l=0;l<x;l++){var i=k[l].src,t=d;t=typeof i!=__csm_st.Constants.udf&&i!=b&&i.length>0;if(t==d)continue;var q=i.toLowerCase();if(__csm_st.Common.GetIndexOf(v,q)==-1){v.push(q);var f=a.GetImageLoadingTime(q,r),g=-1;if(f.startTime>=0&&f.loadingTime>=0)g=f.startTime+f.loadingTime;else if(f.endTime>=0&&f.loadingTime==-1)g=f.endTime;var z=f.loadingTime,h=-1;if(s)h=a.GetImageSize(k[l]);var j={code:a.Codes._none,_size:-1};if(h!=-1){j._size=h;j.code=a.Codes._ok}else if(__csm_pa.D1.A24)j=a.GetSizeBySrc(i,["image"]);var y=c;switch(j.code){case a.Codes._ok:h=j._size;e.totalSize+=parseInt(h);if(g>-1&&g<=n){e.beforeDomCount++;e.beforeDomSize+=h}e.totalCount++;break;case a.Codes._none:e.totalCount++;if(h==-1){w=c;if(g>-1&&g<=n){e.beforeDomCount++;p=c}else m=c}else e.totalSize+=parseInt(h);break;case a.Codes._XDomain:case a.Codes._unknownError:case a.Codes._invalidContent:w=c;if(g>-1&&g<=n){e.beforeDomCount++;p=c}else m=c;e.totalCount++}if(y){e.imagesInfo[u]={__$$type:"ImageInfo",__source:i,__fileSize:h,__loadingTime:z,__isCached:f.isCached,__startTime:f.startTime,__endTime:g};u++}}}if(p)e.beforeDomSize=-1*e.beforeDomSize;if(m)e.totalSize=-1*e.totalSize}return e},GetScriptsInfo:function(){var e={totalSize:0,totalCount:0,scriptsInfo:[],inlineJavaScript:0},g=document.getElementsByTagName("script"),j=g.length;e.domTotalCount=j;if(j>0){var n=0,o=[],p=d,m=Math.min(a.scriptsCollectingLimit,j),r=__csm_st.GetUxScriptsCount();m+=r;for(var f=0;f<m;f++)if(b!=g[f]){var h=new String;h=g[f].src;var k=h.toLowerCase(),s=g[f].id;if(__csm_st.Common.GetIndexOf(o,k)==-1)if(h.length>0&&h!="."&&k.indexOf("javascript:")!=0&&s.indexOf("__csm")==-1){o.push(k);var l=-1,i={code:a.Codes._none,_size:-1};if(__csm_pa.D1.A24)i=a.GetSizeBySrc(h,["script","text/html"]);var q=c;switch(i.code){case a.Codes._ok:l=i._size;e.totalSize+=parseInt(l);e.totalCount++;break;case a.Codes._none:case a.Codes._XDomain:case a.Codes._unknownError:case a.Codes._invalidContent:e.totalCount++;p=c}if(q){e.scriptsInfo[n]={__$$type:"ScriptInfo",__source:g[f].src,__fileSize:l};n++}}}if(p)e.totalSize=-1*e.totalSize}return e},BehaviourUrls:[],ReachedRulesLimit:d,BehaviourUrlsLowerCase:[],CollectRules:function(g,m){if(m==d&&!__csm_st.DisabledContent.HtcDisabled()){var e=b;try{var n=typeof g.rules,o=typeof g.cssRules;if(__csm_st.Common.GetIndexOf([__csm_st.Constants.udf,"unknown"],n)==-1)e=g.rules;else if(__csm_st.Common.GetIndexOf([__csm_st.Constants.udf,"unknown"],o)==-1)e=g.cssRules}catch(p){}if(e!=b)for(var l=a.cssRulesCollectingLimit-1,h=0;h<e.length;h++){var k=e[h].style;if(k!=b){var f=new String;f=k.behavior;if(f!=b&&f.toLowerCase().indexOf("url")==0){var i=f.substr(4,f.length-5),j=i.toLowerCase();if(__csm_st.Common.GetIndexOf(a.BehaviourUrlsLowerCase,j)==-1&&i.indexOf("#")!=0){a.BehaviourUrls.push(i);a.BehaviourUrlsLowerCase.push(j)}}}if(h==l){a.ReachedRulesLimit=c;break}}}},GetCssInfo:function(){var p=__csm_st.BrowserDetect,v=p.isFirefox(),w=p.isExplorer(),f={totalSize:0,totalCount:0,cssStyles:[]},i=document.styleSheets,l=i.length;f.domTotalCount=l;a.BehaviourUrls=[];a.BehaviourUrlsLowerCase=[];if(l>0){for(var o=0,q=[],n=d,s=Math.min(a.cssCollectingLimit,l),h=0;h<s;h++){var t=w;if(i[h]!=b){var g=i[h].href,k=d;if(g!=b&&g!=""){if(g.length>3){var m=g.toLowerCase();if(!__csm_st.StringUtils.EndsWith(g,"__ux.css")){var u=m.substr(g.length-3,3);if(u=="css"&&__csm_st.Common.GetIndexOf(q,m)==-1){k=c;q.push(m)}}}}else k=c;if(k){a.CollectRules(i[h],v);if(g!=b&&g!=""){var e=-1;if(t)try{e=i[h].cssText.length;e=parseInt(e);if(isNaN(e))e=-1}catch(x){}var j={code:a.Codes._none,_size:-1};if(e==-1&&__csm_pa.D1.A24)j=a.GetSizeBySrc(g,["css"]);var r=c;switch(j.code){case a.Codes._ok:e=j._size;f.totalSize+=parseInt(e);f.totalCount++;break;case a.Codes._none:f.totalCount++;if(e==-1)n=c;else f.totalSize+=parseInt(e);break;case a.Codes._XDomain:case a.Codes._unknownError:case a.Codes._invalidContent:f.totalCount++;n=c}if(r){f.cssStyles[o]={__$$type:"CssStyleInfo",__source:g,__fileSize:e};o++}}}}}if(n)f.totalSize=-1*f.totalSize}return f},GetHtcInfo:function(n){var e={totalSize:0,totalCount:0,htcInfo:[],domTotalCount:0},f=a.BehaviourUrls;if(typeof f!=__csm_st.Constants.udf&&f!=b){var k=0,l=d,j=f.length;e.domTotalCount=j;for(var p=Math.min(a.htcCollectingLimit,j),i=0;i<p;i++){var m=f[i],g=-1,h={code:a.Codes._none,_size:-1};if(__csm_pa.D1.A24)h=a.GetSizeBySrc(m,["component"]);var o=c;switch(h.code){case a.Codes._ok:g=h._size;e.totalSize+=parseInt(g);e.totalCount++;break;case a.Codes._none:case a.Codes._XDomain:case a.Codes._unknownError:case a.Codes._invalidContent:e.totalCount++;l=c}var q=a.NeedToIncludeContentItem(g,o,n);if(q){e.htcInfo[k]={__$$type:"HtcInfo",__source:m,__fileSize:g};k++}}f=b;delete a.BehaviourUrls;a.BehaviourUrls=[];if(l)e.totalSize=-1*e.totalSize}return e},GetViewStateSize:function(){var h="__ViewState",g="__VIEWSTATE",e={viewStateSize:0};try{var f=0,c=document.getElementById(g);if(c==b)c=document.getElementById(h);if(c!=b&&c.value!=b)f+=c.value.length;var i=document.getElementById("__VIEWSTATEFIELDCOUNT");if(i!=b)for(var j=parseInt(i.value),d=1;d<j;d++){var a=document.getElementById(g+d);if(a==b)a=document.getElementById(h+d);if(a!=b&&a.value!=b)f+=a.value.length}e.viewStateSize=f}catch(k){e.viewStateSize=-1}return e},ExtendPerformanceEventData:function(c){var k="undefined",j=0,i=-1;if(typeof __csm_pz!=__csm_st.Constants.udf&&typeof __csm_pz.A82!=k&&typeof __csm_pz.A82.A67!=k){i=__csm_pz.A82.A67;if(i>-1)i-=__csm_pz.A82.A41;j-=__csm_pz.A82.A41}var l=__csm_st.AjaxMonitoring.GetUrlBaseString(),n=a.GetViewStateSize(),m=0;c.__contentInformation={__$$type:"ContentInfo",__pageSize:i,__viewStateSize:n.viewStateSize,__inlineScriptsSize:j,__inlineCssStylesSize:m,__disabledContent:__csm_pa.D1.B1};c.__contentInformation.__contentLimits={__$$type:"ContentLimits",__images:__csm_st.A70.imagesCollectingLimit,__scripts:a.scriptsCollectingLimit,__css:a.cssCollectingLimit,__htc:a.htcCollectingLimit,__rules:a.cssRulesCollectingLimit};var f=b,g=b,h=b,e=b;if(d===__csm_st.IsPageComplex()){if(!__csm_st.DisabledContent.ScriptsDisabled()){f=a.GetScriptsInfo();j=f.inlineJavaScript}if(!__csm_st.DisabledContent.CssDisabled())g=a.GetCssInfo();var o=__csm_st.BrowserDetect.isFirefox();if(!__csm_st.DisabledContent.HtcDisabled()&&o==d)h=a.GetHtcInfo();if(!__csm_st.DisabledContent.ImagesDisabed())e=a.GetImagesInfo()}if(e!=b){c.__contentInformation.__imagesInfo=e.imagesInfo;c.__contentInformation.__imagesTotalSize=e.totalSize;c.__contentInformation.__imagesTotalCount=e.totalCount;c.__contentInformation.__imagesBDomCount=e.beforeDomCount;c.__contentInformation.__imagesBDomSize=e.beforeDomSize;c.__contentInformation.__imagesDomTotalCount=e.domTotalCount}else c.__contentInformation.__imagesDomTotalCount=__csm_st.GetImagesCount();if(f!=b){c.__contentInformation.__scriptsInfo=f.scriptsInfo;c.__contentInformation.__scriptsTotalSize=f.totalSize;c.__contentInformation.__scriptsTotalCount=f.totalCount}c.__contentInformation.__scriptsDomTotalCount=__csm_st.GetExtrenalScriptsCount();if(g!=b){c.__contentInformation.__cssStyles=g.cssStyles;c.__contentInformation.__cssTotalSize=g.totalSize;c.__contentInformation.__cssTotalCount=g.totalCount;c.__contentInformation.__cssDomTotalCount=g.domTotalCount}else c.__contentInformation.__cssDomTotalCount=__csm_st.GetExtrenalStyleSheetsCount();if(h!=b){c.__contentInformation.__htcBehaviors=h.htcInfo;c.__contentInformation.__htcTotalSize=h.totalSize;c.__contentInformation.__htcTotalCount=h.totalCount;c.__contentInformation.__htcDomTotalCount=h.domTotalCount}else c.__contentInformation.__htcDomTotalCount=0;__csm_st.PropertiesManager.AddCommonProperty(new __csm_st.PropertyType("isRulesDataCollectingLimitReached",a.ReachedRulesLimit));if(l.length>0)c.__contentInformation.__basePathForRelatives=l;return c}};this.ContentProcessor=a};try{__csm_pf=new __csm_PF;if(typeof __csm_st!="undefined"){__csm_st.IntegrityPolicy.mainPerformanceScriptIsLoaded=true;__csm_st.IntegrityPolicy.RegisterLoadedScript("performance.js");__csm_st.A70.SendPerformanceInfo()}}catch(_exc){}2// SIG // Begin signature block3// SIG // MIIbMwYJKoZIhvcNAQcCoIIbJDCCGyACAQExCzAJBgUr4// SIG // DgMCGgUAMGcGCisGAQQBgjcCAQSgWTBXMDIGCisGAQQB5// SIG // gjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIBAAIB6// SIG // AAIBAAIBAAIBADAhMAkGBSsOAwIaBQAEFCmvc8WQoojt7// SIG // /tpbr9zqHZKCf8HYoIIV8jCCBKAwggOIoAMCAQICCmEa8// SIG // 9eoAAAAAAGowDQYJKoZIhvcNAQEFBQAweTELMAkGA1UE9// SIG // BhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNV10// SIG // BAcTB1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBD11// SIG // b3Jwb3JhdGlvbjEjMCEGA1UEAxMaTWljcm9zb2Z0IENv12// SIG // ZGUgU2lnbmluZyBQQ0EwHhcNMTExMTAxMjIzOTE3WhcN13// SIG // MTMwMjAxMjI0OTE3WjCBgzELMAkGA1UEBhMCVVMxEzAR14// SIG // BgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1JlZG1v15// SIG // bmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlv16// SIG // bjENMAsGA1UECxMETU9QUjEeMBwGA1UEAxMVTWljcm9z17// SIG // b2Z0IENvcnBvcmF0aW9uMIIBIjANBgkqhkiG9w0BAQEF18// SIG // AAOCAQ8AMIIBCgKCAQEAw6kfz3wjfzEeBiWJ3XV5uc+T19// SIG // S2GStpXy76olnXfzS1ptSZDM4DG4pgI3h3Sv8qygYJS420// SIG // x04l/ofYWNIgTi3xOmUuklumXeaVdeA05VAhnH05l7aO21// SIG // RCNmFqZlIOA264r6neLLYAH8KmTIh0UU8R7KzSisuuVX22// SIG // WSbc7MVKbJrmAxopMj8AnoOsJQ2EzN1vtmq7LfeEOm1m23// SIG // Meg2cP+EkpD3QHaeiC5H1isR94/gEmUrvF/vFfz37AFo24// SIG // t0UM7sAEsA63vXhrro3kUPE14p4B0uHrW3GCYSEg89TJ25// SIG // 3hy4AkVlSb5+tTeGp83sWt+4diD8ERNR/PoqUKq0HtA626// SIG // gL5jytyBRwIDAQABo4IBHTCCARkwEwYDVR0lBAwwCgYI27// SIG // KwYBBQUHAwMwHQYDVR0OBBYEFAADpuWixHGigsOPds0s28// SIG // DRLinUooMA4GA1UdDwEB/wQEAwIHgDAfBgNVHSMEGDAW29// SIG // gBRXRXQcXbD2yEMF4IxULY8yp/5IljBWBgNVHR8ETzBN30// SIG // MEugSaBHhkVodHRwOi8vY3JsLm1pY3Jvc29mdC5jb20v31// SIG // cGtpL2NybC9wcm9kdWN0cy9NaWNDb2RTaWdQQ0FfMDgt32// SIG // MzEtMjAxMC5jcmwwWgYIKwYBBQUHAQEETjBMMEoGCCsG33// SIG // AQUFBzAChj5odHRwOi8vd3d3Lm1pY3Jvc29mdC5jb20v34// SIG // cGtpL2NlcnRzL01pY0NvZFNpZ1BDQV8wOC0zMS0yMDEw35// SIG // LmNydDANBgkqhkiG9w0BAQUFAAOCAQEAkPf4eZJpyI9r36// SIG // imDufMGuPoE4UvS6z5mM8C09E/Su9mHwdThOWcY/B0P537// SIG // B3zHU+SRYtaodhR1lIZZsroQwn9sFT8ZFcMOL345w8/+38// SIG // VCdYlDVhB3ltUVewEuHqY3KKFmbrnzkqMwQ1i4PeCl4x39// SIG // vJ8d7jVFDV3Hl98q4J1/Okn740hFMt82bQludlVVrDTF40// SIG // eV1uAtXMl4nzqGh9FOppewtVfQKMxE0wvGL3e6XsoJLw41// SIG // DioOr1ebKUjNtiGl6h3v3An1q2LWDew1X2uZ1LHwd1L542// SIG // d+k/bJhWwFw2oU5eEPSMehGXICAxCHluchZfHDBXm8t843// SIG // olX1cGx47KFDIK7ssDWLGDCCBLowggOioAMCAQICCmEF44// SIG // GZYAAAAAABswDQYJKoZIhvcNAQEFBQAwdzELMAkGA1UE45// SIG // BhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNV46// SIG // BAcTB1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBD47// SIG // b3Jwb3JhdGlvbjEhMB8GA1UEAxMYTWljcm9zb2Z0IFRp48// SIG // bWUtU3RhbXAgUENBMB4XDTExMDcyNTIwNDIxOVoXDTEy49// SIG // MTAyNTIwNDIxOVowgbMxCzAJBgNVBAYTAlVTMRMwEQYD50// SIG // VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25k51// SIG // MR4wHAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24x52// SIG // DTALBgNVBAsTBE1PUFIxJzAlBgNVBAsTHm5DaXBoZXIg53// SIG // RFNFIEVTTjo5RTc4LTg2NEItMDM5RDElMCMGA1UEAxMc54// SIG // TWljcm9zb2Z0IFRpbWUtU3RhbXAgU2VydmljZTCCASIw55// SIG // DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANPLO1Oi56// SIG // n0SjeqtNVnFTineqN5N+AT79qwKjU6n/0bEixQCQ53Vu57// SIG // 7hjogQ4TxdhhAL4foHY7BA0ExQSgqPxDUwahBAS5C5KY58// SIG // AmI479QzEvcrPXvvrUVXhZUgn9djNJxiRo6+ruDZnjn259// SIG // qVX9z+d35jUT71zov0iTTxpDB1g4in+FFGzqydBLeoJu60// SIG // y9MVYAgUiZSoWz86yT8gfW0vWBp9yoo4vMPCOWjYLVga61// SIG // I+0qEAhaIIyCpe3Rl0WShczDN4PfDZh8xdO24JlT2HgI62// SIG // 9eUjIQdihlpqaRn9cPlTNIH3JTEZhoeLwFWa/apMNRX963// SIG // W+mVyatTmClfLKXhJQ9kxfKwJ3UCAwEAAaOCAQkwggEF64// SIG // MB0GA1UdDgQWBBR5I+ehDb5VLGgYKWKCZ9bz4TY4WjAf65// SIG // BgNVHSMEGDAWgBQjNPjZUkZwCu1A+3b7syuwwzWzDzBU66// SIG // BgNVHR8ETTBLMEmgR6BFhkNodHRwOi8vY3JsLm1pY3Jv67// SIG // c29mdC5jb20vcGtpL2NybC9wcm9kdWN0cy9NaWNyb3Nv68// SIG // ZnRUaW1lU3RhbXBQQ0EuY3JsMFgGCCsGAQUFBwEBBEww69// SIG // SjBIBggrBgEFBQcwAoY8aHR0cDovL3d3dy5taWNyb3Nv70// SIG // ZnQuY29tL3BraS9jZXJ0cy9NaWNyb3NvZnRUaW1lU3Rh71// SIG // bXBQQ0EuY3J0MBMGA1UdJQQMMAoGCCsGAQUFBwMIMA0G72// SIG // CSqGSIb3DQEBBQUAA4IBAQBHwnaBWzHdb9M8mfJ6bH6X73// SIG // E1AsBRcbELhEobWM9FbPvbAhtGRtYRzY7ujr9ZLuQ6IY74// SIG // RMP6+u+ttlx/l21LtUP7J2F4CFR8sfmvmAq0dMSq6C1Q75// SIG // xH3+fU6hmdYnKLeu2N+xj4Mijs7zefxhFG2/68yEsN+j76// SIG // u1sFt+pU9WIdbCemY0v646H6u9+FlmVpU7C2cZhkJma977// SIG // xfFcYryR9D2cS0IADc84BRQmWtwqBUt/apk42N1zmaLO78// SIG // jFAknqTr9T+KeMxUmV0lZqRBBiivScS0UpTs3gKDZP5N79// SIG // 1P9LovwpgNvuP6s87TOIyr8iYNBcOwSwCrSYbTynOk+a80// SIG // 0QEWEWKKQXagMIIGBzCCA++gAwIBAgIKYRZoNAAAAAAA81// SIG // HDANBgkqhkiG9w0BAQUFADBfMRMwEQYKCZImiZPyLGQB82// SIG // GRYDY29tMRkwFwYKCZImiZPyLGQBGRYJbWljcm9zb2Z083// SIG // MS0wKwYDVQQDEyRNaWNyb3NvZnQgUm9vdCBDZXJ0aWZp84// SIG // Y2F0ZSBBdXRob3JpdHkwHhcNMDcwNDAzMTI1MzA5WhcN85// SIG // MjEwNDAzMTMwMzA5WjB3MQswCQYDVQQGEwJVUzETMBEG86// SIG // A1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9u87// SIG // ZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9u88// SIG // MSEwHwYDVQQDExhNaWNyb3NvZnQgVGltZS1TdGFtcCBQ89// SIG // Q0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB90// SIG // AQCfoWyx39tIkip8ay4Z4b3i48WZUSNQrc7dGE4kD+7R91// SIG // p9FMrXQwIBHrB9VUlRVJlBtCkq6YXDAm2gBr6Hu97IkH92// SIG // D/cOBJjwicwfyzMkh53y9GccLPx754gd6udOo6HBI1PK93// SIG // jfpFzwnQXq/QsEIEovmmbJNn1yjcRlOwhtDlKEYuJ6yG94// SIG // T1VSDOQDLPtqkJAwbofzWTCd+n7Wl7PoIZd++NIT8wi395// SIG // U21StEWQn0gASkdmEScpZqiX5NMGgUqi+YSnEUcUCYKf96// SIG // hO1VeP4Bmh1QCIUAEDBG7bfeI0a7xC1Un68eeEExd8yb97// SIG // 3zuDk6FhArUdDbH895uyAc4iS1T/+QXDwiALAgMBAAGj98// SIG // ggGrMIIBpzAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW99// SIG // BBQjNPjZUkZwCu1A+3b7syuwwzWzDzALBgNVHQ8EBAMC100// SIG // AYYwEAYJKwYBBAGCNxUBBAMCAQAwgZgGA1UdIwSBkDCB101// SIG // jYAUDqyCYEBWJ5flJRP8KuEKU5VZ5KShY6RhMF8xEzAR102// SIG // BgoJkiaJk/IsZAEZFgNjb20xGTAXBgoJkiaJk/IsZAEZ103// SIG // FgltaWNyb3NvZnQxLTArBgNVBAMTJE1pY3Jvc29mdCBS104// SIG // b290IENlcnRpZmljYXRlIEF1dGhvcml0eYIQea0WoUqg105// SIG // pa1Mc1j0BxMuZTBQBgNVHR8ESTBHMEWgQ6BBhj9odHRw106// SIG // Oi8vY3JsLm1pY3Jvc29mdC5jb20vcGtpL2NybC9wcm9k107// SIG // dWN0cy9taWNyb3NvZnRyb290Y2VydC5jcmwwVAYIKwYB108// SIG // BQUHAQEESDBGMEQGCCsGAQUFBzAChjhodHRwOi8vd3d3109// SIG // Lm1pY3Jvc29mdC5jb20vcGtpL2NlcnRzL01pY3Jvc29m110// SIG // dFJvb3RDZXJ0LmNydDATBgNVHSUEDDAKBggrBgEFBQcD111// SIG // CDANBgkqhkiG9w0BAQUFAAOCAgEAEJeKw1wDRDbd6bSt112// SIG // d9vOeVFNAbEudHFbbQwTq86+e4+4LtQSooxtYrhXAstO113// SIG // IBNQmd16QOJXu69YmhzhHQGGrLt48ovQ7DsB7uK+jwoF114// SIG // yI1I4vBTFd1Pq5Lk541q1YDB5pTyBi+FA+mRKiQicPv2115// SIG // /OR4mS4N9wficLwYTp2OawpylbihOZxnLcVRDupiXD8W116// SIG // mIsgP+IHGjL5zDFKdjE9K3ILyOpwPf+FChPfwgphjvDX117// SIG // uBfrTot/xTUrXqO/67x9C0J71FNyIe4wyrt4ZVxbARcK118// SIG // FA7S2hSY9Ty5ZlizLS/n+YWGzFFW6J1wlGysOUzU9nm/119// SIG // qhh6YinvopspNAZ3GmLJPR5tH4LwC8csu89Ds+X57H21120// SIG // 46SodDW4TsVxIxImdgs8UoxxWkZDFLyzs7BNZ8ifQv+A121// SIG // eSGAnhUwZuhCEl4ayJ4iIdBD6Svpu/RIzCzU2DKATCYq122// SIG // SCRfWupW76bemZ3KOm+9gSd0BhHudiG/m4LBJ1S2sWo9123// SIG // iaF2YbRuoROmv6pH8BJv/YoybLL+31HIjCPJZr2dHYcS124// SIG // ZAI9La9Zj7jkIeW1sMpjtHhUBdRBLlCslLCleKuzoJZ1125// SIG // GtmShxN1Ii8yqAhuoFuMJb+g74TKIdbrHk/Jmu5J4PcB126// SIG // ZW+JC33Iacjmbuqnl84xKf8OxVtc2E0bodj6L54/LlUW127// SIG // a8kTo/0wggaBMIIEaaADAgECAgphFQgnAAAAAAAMMA0G128// SIG // CSqGSIb3DQEBBQUAMF8xEzARBgoJkiaJk/IsZAEZFgNj129// SIG // b20xGTAXBgoJkiaJk/IsZAEZFgltaWNyb3NvZnQxLTAr130// SIG // BgNVBAMTJE1pY3Jvc29mdCBSb290IENlcnRpZmljYXRl131// SIG // IEF1dGhvcml0eTAeFw0wNjAxMjUyMzIyMzJaFw0xNzAx132// SIG // MjUyMzMyMzJaMHkxCzAJBgNVBAYTAlVTMRMwEQYDVQQI133// SIG // EwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4w134// SIG // HAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24xIzAh135// SIG // BgNVBAMTGk1pY3Jvc29mdCBDb2RlIFNpZ25pbmcgUENB136// SIG // MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA137// SIG // n43fhTeMsQZWZjZO1ArrNiORHq+rjVjpxM/BnzoKJMTE138// SIG // xF6w7hUUxfo+mTNrGWly9HwFX+WZJUTXNRmKkNwojpAM139// SIG // 79WQYa3e3BhwLYPJb6+FLPjdubkw/XF4HIP9yKm5gmcN140// SIG // erjBCcK8FpdXPxyY02nXMJCQkI0wH9gm1J57iNniCe2X141// SIG // SUXrBFKBdXu4tSK4Lla718+pTjwKg6KoOsWttgEOas8i142// SIG // tCMfbNUn57d+wbTVMq15JRxChuKdhfRX2htZLy0mkinF143// SIG // s9eFo55gWpTme5x7XoI0S23/1O4n0KLc0ZAMzn0OFXyI144// SIG // rDTHwGyYhErJRHloKN8igw24iixIYeL+EQIDAQABo4IC145// SIG // IzCCAh8wEAYJKwYBBAGCNxUBBAMCAQAwHQYDVR0OBBYE146// SIG // FFdFdBxdsPbIQwXgjFQtjzKn/kiWMAsGA1UdDwQEAwIB147// SIG // xjAPBgNVHRMBAf8EBTADAQH/MIGYBgNVHSMEgZAwgY2A148// SIG // FA6sgmBAVieX5SUT/CrhClOVWeSkoWOkYTBfMRMwEQYK149// SIG // CZImiZPyLGQBGRYDY29tMRkwFwYKCZImiZPyLGQBGRYJ150// SIG // bWljcm9zb2Z0MS0wKwYDVQQDEyRNaWNyb3NvZnQgUm9v151// SIG // dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHmCEHmtFqFKoKWt152// SIG // THNY9AcTLmUwUAYDVR0fBEkwRzBFoEOgQYY/aHR0cDov153// SIG // L2NybC5taWNyb3NvZnQuY29tL3BraS9jcmwvcHJvZHVj154// SIG // dHMvbWljcm9zb2Z0cm9vdGNlcnQuY3JsMFQGCCsGAQUF155// SIG // BwEBBEgwRjBEBggrBgEFBQcwAoY4aHR0cDovL3d3dy5t156// SIG // aWNyb3NvZnQuY29tL3BraS9jZXJ0cy9NaWNyb3NvZnRS157// SIG // b290Q2VydC5jcnQwdgYDVR0gBG8wbTBrBgkrBgEEAYI3158// SIG // FS8wXjBcBggrBgEFBQcCAjBQHk4AQwBvAHAAeQByAGkA159// SIG // ZwBoAHQAIACpACAAMgAwADAANgAgAE0AaQBjAHIAbwBz160// SIG // AG8AZgB0ACAAQwBvAHIAcABvAHIAYQB0AGkAbwBuAC4w161// SIG // EwYDVR0lBAwwCgYIKwYBBQUHAwMwDQYJKoZIhvcNAQEF162// SIG // BQADggIBADC8sCCkYqCn7zkmYT3crMaZ0IbELvWDMmVe163// SIG // Ij6b1ob46LafyovWO3ULoZE+TN1kdIxJ8oiMGGds/hVm164// SIG // Rrg6RkKXyJE31CSx56zT6kEUg3fTyU8FX6MUUr+WpC8+165// SIG // VlsQdc5Tw84FVGm0ZckkpQ/hJbgauU3lArlQHk+zmAwd166// SIG // lQLuIlmtIssFdAsERXsEWeDYD7PrTPhg3cJ4ntG6n2v3167// SIG // 8+5+RBFA0r26m0sWCG6kvlXkpjgSo0j0HFV6iiDRff6R168// SIG // 25SPL8J7a6ZkhU+j5Sw0KV0Lv/XHOC/EIMRWMfZpzoX4169// SIG // CpHs0NauujgFDOtuT0ycAymqovwYoCkMDVxcViNX2hyW170// SIG // DcgmNsFEy+Xh5m+J54/pmLVz03jj7aMBPHTlXrxs9iGJ171// SIG // ZwXsl521sf2vpulypcM04S+f+fRqOeItBIJb/NCcrnyd172// SIG // EfnmtVMZdLo5SjnrfUKzSjs3PcJKeyeY5+JOmxtKVDhq173// SIG // Ize+ardI7upCDUkkkY63BC6Xb+TnRbuPTf1g2ddZwtiA174// SIG // 1mA0e7ehkyD+gbiqpVwJ6YoNvihNftfoD+1leNExX7lm175// SIG // 299C5wvMAgeN3/8gBqNFZbSzMo0ukeJNtKnJ+rxrBA6y176// SIG // n+qf3qTJCpb0jffYmKjwhQIIWaQgpiwLGvJSBu1p5WQY177// SIG // G+Cjq97KfBRhQ7hl9TajVRMrZyxNGzBMMYIErTCCBKkC178// SIG // AQEwgYcweTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldh179// SIG // c2hpbmd0b24xEDAOBgNVBAcTB1JlZG1vbmQxHjAcBgNV180// SIG // BAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEjMCEGA1UE181// SIG // AxMaTWljcm9zb2Z0IENvZGUgU2lnbmluZyBQQ0ECCmEa182// SIG // 9eoAAAAAAGowCQYFKw4DAhoFAKCB2jAZBgkqhkiG9w0B183// SIG // CQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4w184// SIG // DAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUqfJp185// SIG // fvjzruFJ2s4S0PhWiHeKlMEwegYKKwYBBAGCNwIBDDFs186// SIG // MGqgTIBKAFMAeQBzAHQAZQBtACAAQwBlAG4AdABlAHIA187// SIG // IABPAHAAZQByAGEAdABpAG8AbgBzACAATQBhAG4AYQBn188// SIG // AGUAcgAgADIAMAAxADKhGoAYaHR0cDovL3d3dy5taWNy189// SIG // b3NvZnQuY29tMA0GCSqGSIb3DQEBAQUABIIBAA1/cGDA190// SIG // yIZS6Ei4HQPUcft/1fMB9vgYsrjxc9AMqcD7d06Ud9uH191// SIG // k/GN4TxaC7HXv9vBeqFw63PAiYv47dp+OObmjC61U0uV192// SIG // Om7r7cULLHWns4A950r9ocns4vpk0P83+XZZFsTPUt7O193// SIG // Xf4jZQrDzxpueU2oC5O3gVjjikBgsen8wkK2nKlptEpp194// SIG // +jH7qvtN+yOYo2FZKZ73un+up2Dvv13XTMY9Tz6aKptv195// SIG // uCV4pLLaqkzJJrrurKvjrqiXRmUYMt5OTNNBztqYd/WV196// SIG // eDbugw0qHGvToXoxm0kEELq1r3+fws+Cf7fkfhsp/STP197// SIG // cZA+JpoXKOt/kBriM4e2iH8WriqhggIdMIICGQYJKoZI198// SIG // hvcNAQkGMYICCjCCAgYCAQEwgYUwdzELMAkGA1UEBhMC199// SIG // VVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcT200// SIG // B1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jw201// SIG // b3JhdGlvbjEhMB8GA1UEAxMYTWljcm9zb2Z0IFRpbWUt202// SIG // U3RhbXAgUENBAgphBRmWAAAAAAAbMAcGBSsOAwIaoF0w203// SIG // GAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG204// SIG // 9w0BCQUxDxcNMTIwMTI2MDc0MjM5WjAjBgkqhkiG9w0B205// SIG // CQQxFgQU4X45M3gcegNfNmgRmHW5D3lwEiMwDQYJKoZI206// SIG // hvcNAQEFBQAEggEAkSN4Cicb8TN3QsrJTEZT7T/1MiD0207// SIG // CZP7PMaRaziWnXDHSseTS1+w8QyMq4QTIbsoUCabNSsw208// SIG // W64vzNHqMMu7kmgEa9giiRcYLG8amqn8NRo+KGBDSoqb209// SIG // hJGqMwtOyQzOpdtFFkdr8cENzO4wY1yDDyajFYxK2Q0O210// SIG // 6DSyC2jhAqpxvswpioVVcwye3U11NiWx9AwAmilvjLhf211// SIG // rum7aAUJYIydTbapOShWjF97gAK8lPBPXUQfNHIzEXyx212// SIG // aN8q1BcX88x0WS/YSOU8EXEFTKPfTvuQ40S2JqDiLkNJ213// SIG // lT+A6AjAxSrdRMMkZE3JxqIUZO/UJINWExNWp3FYNVpg214// SIG // OAtX8w==
...
server.js
Source:server.js
...36 setProxiedUrl = function(req) {37 if (req.proxiedUrl) {38 return;39 }40 req.proxiedUrl = uri.removeDefaultPort(req.url);41 return req.url = uri.getPath(req.url);42 };43 notSSE = function(req, res) {44 return req.headers.accept !== "text/event-stream" && compression.filter(req, res);45 };46 Server = (function() {47 function Server() {48 if (!(this instanceof Server)) {49 return new Server();50 }51 this._request = null;52 this._middleware = null;53 this._server = null;54 this._socket = null;...
server-base.js
Source:server-base.js
...67 // and slice out the host/origin68 // and only leave the path which is69 // how browsers would normally send70 // use their url71 req.proxiedUrl = network_1.uri.removeDefaultPort(req.url).format();72 req.url = network_1.uri.getPath(req.url);73};74const notSSE = (req, res) => {75 return (req.headers.accept !== 'text/event-stream') && compression_1.default.filter(req, res);76};77class ServerBase {78 constructor() {79 this.ensureProp = class_helpers_1.ensureProp;80 this.isListening = false;81 // @ts-ignore82 this.request = (0, request_1.default)();83 this.socketAllowed = new socket_allowed_1.SocketAllowed();84 this._middleware = null;85 this._baseUrl = null;...
index.js
Source:index.js
1"use strict";2const anyMatch = require("any-match");3const deepFreeze = require("deep-freeze-node");4const evaluateValue = require("evaluate-value");5const isURL = require("isurl");6const stripWWW = require("strip-www");7const defaultPorts = { "ftps:":990, "git:":9418, "scp:":22, "sftp:":22, "ssh:":22 };8const indexFilenames = ["index.html"];9const queryNames = [];10const EMPTY_QUERY_VALUE = /([^&\?])=&/g;11const ENCODED_SPACE = /%20/g;12const MULTIPLE_SLASHES = /\/{2,}/g;13const TRAILING_EQUALS = /([^&\?])=$/;14const TRAILING_QUESTION = /\?#?(?:.+)?$/;15const defaultValue = (customOptions, optionName, ...args) =>16{17 const defaultOption = evaluateValue(COMMON_PROFILE[optionName], ...args);18 return evaluateValue(customOptions?.[optionName], ...args) ?? defaultOption;19};20const filterCommon = url => url.protocol==="http:" || url.protocol==="https:";21const filterSafe = url => url.protocol === "mailto:";22const filterSpecCompliant = url =>23{24 return filterSafe(url) || url.protocol==="http:" || url.protocol==="https:" || url.protocol==="ws:" || url.protocol==="wss:";25};26const CAREFUL_PROFILE =27{28 clone: true,29 defaultPorts,30 indexFilenames,31 plusQueries: true,32 queryNames,33 removeAuth: false,34 removeDefaultPort: true,35 removeEmptyHash: true,36 removeEmptyQueries: filterSafe,37 removeEmptyQueryNames: filterSafe,38 removeEmptyQueryValues: filterSafe,39 removeEmptySegmentNames: false,40 removeHash: false,41 removeIndexFilename: false,42 removeQueryNames: false,43 removeQueryOddities: true,44 removeRootTrailingSlash: true,45 removeTrailingSlash: false,46 removeWWW: false,47 sortQueries: filterSafe,48 stringify: true49};50const COMMON_PROFILE =51{52 clone: true,53 defaultPorts,54 indexFilenames,55 plusQueries: true,56 queryNames,57 removeAuth: false,58 removeDefaultPort: true,59 removeEmptyHash: true,60 removeEmptyQueries: filterSpecCompliant,61 removeEmptyQueryNames: filterSafe,62 removeEmptyQueryValues: filterSafe,63 removeEmptySegmentNames: false,64 removeHash: false,65 removeIndexFilename: filterCommon,66 removeQueryNames: false,67 removeQueryOddities: true,68 removeRootTrailingSlash: true,69 removeTrailingSlash: false,70 removeWWW: filterCommon,71 sortQueries: filterSpecCompliant,72 stringify: true73};74const minURL = (url, options) =>75{76 if (!isURL.lenient(url))77 {78 throw new TypeError("Invalid URL");79 }80 if (defaultValue(options, "clone", url))81 {82 url = new URL(url);83 }84 if (defaultValue(options, "removeAuth", url))85 {86 url.password = "";87 url.username = "";88 }89 if (defaultValue(options, "removeDefaultPort", url))90 {91 const defaultPorts = defaultValue(options, "defaultPorts");92 if (defaultPorts[url.protocol] === parseInt(url.port))93 {94 url.port = "";95 }96 }97 if (defaultValue(options, "removeIndexFilename", url))98 {99 const indexFilenames = defaultValue(options, "indexFilenames");100 const pathnameSegments = url.pathname.split("/");101 const lastPathnameSegment = pathnameSegments[pathnameSegments.length - 1];102 if (anyMatch(lastPathnameSegment, indexFilenames))103 {104 url.pathname = url.pathname.slice(0, -lastPathnameSegment.length);105 }106 }107 if (defaultValue(options, "removeEmptySegmentNames", url))108 {109 url.pathname = url.pathname.replace(MULTIPLE_SLASHES, "/");110 }111 if (defaultValue(options, "removeHash", url))112 {113 url.hash = "";114 }115 else if (url.hash==="" && url.href.endsWith("#"))116 {117 if (defaultValue(options, "removeEmptyHash", url))118 {119 // Force `href` to update120 url.hash = "";121 }122 }123 if (url.search !== "")124 {125 // If not a partial implementation126 if (url.searchParams !== undefined)127 {128 // Also, if not a partial implementation129 if (url.searchParams.sort !== undefined)130 {131 if (defaultValue(options, "sortQueries", url))132 {133 url.searchParams.sort();134 }135 }136 const removeEmptyQueries = defaultValue(options, "removeEmptyQueries", url);137 const removeEmptyQueryNames = defaultValue(options, "removeEmptyQueryNames", url);138 const removeEmptyQueryValues = defaultValue(options, "removeEmptyQueryValues", url);139 if (removeEmptyQueries || removeEmptyQueryNames || removeEmptyQueryValues)140 {141 // Cache original params142 const params = Array.from(url.searchParams);143 // Clear all params144 // @todo construct a new `URLSearchParams` instance when feasible, to avoid mutliple re-stringifcations145 // https://github.com/nodejs/node/issues/10481146 url.search = "";147 // Rebuild params148 // `searchParams.delete()` will not remove individual values149 params.filter(([name, value]) =>150 {151 const isRemovableQuery = removeEmptyQueries && name==="" && value==="";152 const isRemovableQueryName = removeEmptyQueryNames && name==="" && value!=="";153 const isRemovableQueryValue = removeEmptyQueryValues && name!=="" && value==="";154 return !isRemovableQuery && !isRemovableQueryName && !isRemovableQueryValue;155 })156 .forEach(([name, value]) => url.searchParams.append(name, value));157 }158 if (defaultValue(options, "removeQueryNames", url))159 {160 const queryNames = defaultValue(options, "queryNames");161 Array.from(url.searchParams.keys()).forEach(param =>162 {163 if (anyMatch(param, queryNames))164 {165 url.searchParams.delete(param);166 }167 });168 }169 }170 }171 if (defaultValue(options, "removeQueryOddities", url))172 {173 if (url.search !== "")174 {175 url.search = url.search176 .replace(EMPTY_QUERY_VALUE, "$1&")177 .replace(TRAILING_EQUALS, "$1");178 }179 else if (TRAILING_QUESTION.test(url.href))180 {181 // Force `href` to update182 url.search = "";183 }184 }185 if (url.search!=="" && defaultValue(options, "plusQueries", url))186 {187 // @todo https://github.com/whatwg/url/issues/18188 url.search = url.search.replace(ENCODED_SPACE, "+");189 }190 if (defaultValue(options, "removeWWW", url))191 {192 // @todo "www.www.domain.com" doesn't get stripped correctly193 url.hostname = stripWWW(url.hostname);194 }195 if (!defaultValue(options, "stringify"))196 {197 return url;198 }199 else if (defaultValue(options, "removeTrailingSlash", url))200 {201 // Avoid changing "//" to "/"202 if (url.pathname.endsWith("/") && !url.pathname.endsWith("//"))203 {204 return url.href.replace(url.host + url.pathname, url.host + url.pathname.slice(0,-1));205 }206 }207 else if (defaultValue(options, "removeRootTrailingSlash", url))208 {209 if (url.pathname === "/")210 {211 return url.href.replace(url.host + url.pathname, url.host);212 }213 }214 return url.href;215};216minURL.CAREFUL_PROFILE = CAREFUL_PROFILE;217minURL.COMMON_PROFILE = COMMON_PROFILE;...
buffers.js
Source:buffers.js
...9const network_1 = require("../../../../network");10const debug = (0, debug_1.default)('cypress:proxy:http:util:buffers');11const stripPort = (url) => {12 try {13 return network_1.uri.removeDefaultPort(url).format();14 }15 catch (e) {16 return url;17 }18};19class HttpBuffers {20 constructor() {21 this.buffer = undefined;22 }23 reset() {24 debug('resetting buffers');25 delete this.buffer;26 }27 set(obj) {...
uri.js
Source:uri.js
1(function() {2 var DEFAULT_PORTS, getPath, removeDefaultPort, stripProtocolAndDefaultPorts, url,3 indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };4 url = require("url");5 DEFAULT_PORTS = ["443", "80"];6 stripProtocolAndDefaultPorts = function(urlToCheck) {7 var host, hostname, port, ref;8 ref = url.parse(urlToCheck), host = ref.host, hostname = ref.hostname, port = ref.port;9 if (indexOf.call(DEFAULT_PORTS, port) >= 0) {10 return hostname;11 }12 return host;13 };14 removeDefaultPort = function(urlToCheck) {15 var parsed, ref;16 parsed = url.parse(urlToCheck);17 if (ref = parsed.port, indexOf.call(DEFAULT_PORTS, ref) >= 0) {18 parsed.host = null;19 parsed.port = null;20 }21 return url.format(parsed);22 };23 getPath = function(urlToCheck) {24 return url.parse(urlToCheck).path;25 };26 module.exports = {27 getPath: getPath,28 removeDefaultPort: removeDefaultPort,29 stripProtocolAndDefaultPorts: stripProtocolAndDefaultPorts30 };...
Using AI Code Generation
1cy.removeDefaultPort();2cy.removeDefaultPort();3cy.removeDefaultPort();4Cypress.Commands.add('removeDefaultPort', () => {5 cy.window().then(win => {6 win.location.port = null;7 });8});
Using AI Code Generation
1cy.removeDefaultPort();2Cypress.Commands.add('removeDefaultPort', () => {3 cy.on('window:before:load', (win) => {4 delete win.location.port;5 });6});
Using AI Code Generation
1context('Remove Default Port', () => {2 it('Remove Default Port', () => {3 cy.removeDefaultPort()4 })5})6Cypress.Commands.add('removeDefaultPort', () => {7 cy.window().then((win) => {8 win.history.replaceState({}, '', win.location.href.replace(':3000', ''))9 })10})
Using AI Code Generation
1Cypress.Commands.add('removeDefaultPort', (url) => {2 cy.log('removeDefaultPort');3 cy.log(`url: ${url}`);4 cy.task('removeDefaultPort', url);5});6module.exports = (on, config) => {7 on('task', {8 removeDefaultPort(url) {9 cy.log('removeDefaultPort');10 cy.log(`url: ${url}`);11 const newUrl = url.replace(':3000', '');12 cy.log(`newUrl: ${newUrl}`);13 return newUrl;14 },15 });16};
Using AI Code Generation
1cy.removeDefaultPort().then((port) => {2 cy.request({3 }).then((response) => {4 expect(response.status).to.eq(200);5 });6});7Cypress.Commands.add("removeDefaultPort", () => {8 return cy.window().then((win) => {9 const { location } = win;10 const port = location.port ? `:${location.port}` : "";11 return port;12 });13});
Using AI Code Generation
1const cypress = require('cypress');2const cypress = require('cypress');3const cypress = require('cypress');4const cypress = require('cypress');5const cypress = require('cypress');6const cypress = require('cypress');7const cypress = require('cypress');8const cypress = require('cypress');
Using AI Code Generation
1cy.removeDefaultPort();2Cypress.Commands.add('removeDefaultPort', () => {3 cy.window().then((win) => {4 win.history.replaceState(5 );6 });7});
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!