| @@ 507-552 (lines=46) @@ | ||
| 504 | * comment: function(text) {} |
|
| 505 | * } |
|
| 506 | */ |
|
| 507 | function htmlSanitizeWriterImpl(buf, uriValidator) { |
|
| 508 | var ignoreCurrentElement = false; |
|
| 509 | var out = bind(buf, buf.push); |
|
| 510 | return { |
|
| 511 | start: function(tag, attrs) { |
|
| 512 | tag = lowercase(tag); |
|
| 513 | if (!ignoreCurrentElement && blockedElements[tag]) { |
|
| 514 | ignoreCurrentElement = tag; |
|
| 515 | } |
|
| 516 | if (!ignoreCurrentElement && validElements[tag] === true) { |
|
| 517 | out('<'); |
|
| 518 | out(tag); |
|
| 519 | forEach(attrs, function(value, key) { |
|
| 520 | var lkey = lowercase(key); |
|
| 521 | var isImage = (tag === 'img' && lkey === 'src') || (lkey === 'background'); |
|
| 522 | if (validAttrs[lkey] === true && |
|
| 523 | (uriAttrs[lkey] !== true || uriValidator(value, isImage))) { |
|
| 524 | out(' '); |
|
| 525 | out(key); |
|
| 526 | out('="'); |
|
| 527 | out(encodeEntities(value)); |
|
| 528 | out('"'); |
|
| 529 | } |
|
| 530 | }); |
|
| 531 | out('>'); |
|
| 532 | } |
|
| 533 | }, |
|
| 534 | end: function(tag) { |
|
| 535 | tag = lowercase(tag); |
|
| 536 | if (!ignoreCurrentElement && validElements[tag] === true && voidElements[tag] !== true) { |
|
| 537 | out('</'); |
|
| 538 | out(tag); |
|
| 539 | out('>'); |
|
| 540 | } |
|
| 541 | // eslint-disable-next-line eqeqeq |
|
| 542 | if (tag == ignoreCurrentElement) { |
|
| 543 | ignoreCurrentElement = false; |
|
| 544 | } |
|
| 545 | }, |
|
| 546 | chars: function(chars) { |
|
| 547 | if (!ignoreCurrentElement) { |
|
| 548 | out(encodeEntities(chars)); |
|
| 549 | } |
|
| 550 | } |
|
| 551 | }; |
|
| 552 | } |
|
| 553 | ||
| 554 | ||
| 555 | /** |
|
| @@ 457-502 (lines=46) @@ | ||
| 454 | * comment: function(text) {} |
|
| 455 | * } |
|
| 456 | */ |
|
| 457 | function htmlSanitizeWriterImpl(buf, uriValidator) { |
|
| 458 | var ignoreCurrentElement = false; |
|
| 459 | var out = bind(buf, buf.push); |
|
| 460 | return { |
|
| 461 | start: function(tag, attrs) { |
|
| 462 | tag = lowercase(tag); |
|
| 463 | if (!ignoreCurrentElement && blockedElements[tag]) { |
|
| 464 | ignoreCurrentElement = tag; |
|
| 465 | } |
|
| 466 | if (!ignoreCurrentElement && validElements[tag] === true) { |
|
| 467 | out('<'); |
|
| 468 | out(tag); |
|
| 469 | forEach(attrs, function(value, key) { |
|
| 470 | var lkey = lowercase(key); |
|
| 471 | var isImage = (tag === 'img' && lkey === 'src') || (lkey === 'background'); |
|
| 472 | if (validAttrs[lkey] === true && |
|
| 473 | (uriAttrs[lkey] !== true || uriValidator(value, isImage))) { |
|
| 474 | out(' '); |
|
| 475 | out(key); |
|
| 476 | out('="'); |
|
| 477 | out(encodeEntities(value)); |
|
| 478 | out('"'); |
|
| 479 | } |
|
| 480 | }); |
|
| 481 | out('>'); |
|
| 482 | } |
|
| 483 | }, |
|
| 484 | end: function(tag) { |
|
| 485 | tag = lowercase(tag); |
|
| 486 | if (!ignoreCurrentElement && validElements[tag] === true && voidElements[tag] !== true) { |
|
| 487 | out('</'); |
|
| 488 | out(tag); |
|
| 489 | out('>'); |
|
| 490 | } |
|
| 491 | // eslint-disable-next-line eqeqeq |
|
| 492 | if (tag == ignoreCurrentElement) { |
|
| 493 | ignoreCurrentElement = false; |
|
| 494 | } |
|
| 495 | }, |
|
| 496 | chars: function(chars) { |
|
| 497 | if (!ignoreCurrentElement) { |
|
| 498 | out(encodeEntities(chars)); |
|
| 499 | } |
|
| 500 | } |
|
| 501 | }; |
|
| 502 | } |
|
| 503 | ||
| 504 | ||
| 505 | /** |
|