MCPcopy Create free account
hub / github.com/binux/qiandao / parse

Function parse

web/static/node_components.js:334–489  ·  view source on GitHub ↗
(str, strict)

Source from the content-addressed store, hash-verified

332}
333
334function parse(str, strict) {
335 str = str.trim();
336
337 // S4.1.1 Trailing semi-colons are not part of the specification.
338 // If we are not in strict mode we remove the trailing semi-colons.
339 var semiColonCheck = TRAILING_SEMICOLON.exec(str);
340 if (semiColonCheck) {
341 if (strict) {
342 return;
343 }
344 str = str.slice(0, semiColonCheck.index);
345 }
346
347 // We use a regex to parse the "name-value-pair" part of S5.2
348 var firstSemi = str.indexOf(';'); // S5.2 step 1
349 var pairRx = strict ? COOKIE_PAIR_STRICT : COOKIE_PAIR;
350 var result = pairRx.exec(firstSemi === -1 ? str : str.substr(0,firstSemi));
351
352 // Rx satisfies the "the name string is empty" and "lacks a %x3D ("=")"
353 // constraints as well as trimming any whitespace.
354 if (!result) {
355 return;
356 }
357
358 var c = new Cookie();
359 c.key = result[1]; // the regexp should trim() already
360 c.value = result[3]; // [2] is quotes or empty-string
361
362 if (firstSemi === -1) {
363 return c;
364 }
365
366 // S5.2.3 "unparsed-attributes consist of the remainder of the set-cookie-string
367 // (including the %x3B (";") in question)." plus later on in the same section
368 // "discard the first ";" and trim".
369 var unparsed = str.slice(firstSemi).replace(/^\s*;\s*/,'').trim();
370
371 // "If the unparsed-attributes string is empty, skip the rest of these
372 // steps."
373 if (unparsed.length === 0) {
374 return c;
375 }
376
377 /*
378 * S5.2 says that when looping over the items "[p]rocess the attribute-name
379 * and attribute-value according to the requirements in the following
380 * subsections" for every item. Plus, for many of the individual attributes
381 * in S5.3 it says to use the "attribute-value of the last attribute in the
382 * cookie-attribute-list". Therefore, in this implementation, we overwrite
383 * the previous value.
384 */
385 var cookie_avs = unparsed.split(/\s*;\s*/);
386 while (cookie_avs.length) {
387 var av = cookie_avs.shift();
388
389 if (strict && !EXTENSION_AV.test(av)) {
390 return;
391 }

Callers

nothing calls this directly

Calls 1

parseDateFunction · 0.85

Tested by

no test coverage detected