Implement createTextNode, do more relaxed escaping there, update testcase.

pull/135/head
Gijs Kruitbosch 9 years ago
parent 37a8cd4171
commit 0ff82de0f4

@ -48,6 +48,12 @@
"'": "'",
};
function encodeTextContentHTML(s) {
return s.replace(/[&<>]/g, function(x) {
return reverseEntityTable[x];
});
}
function encodeHTML(s) {
return s.replace(/[&<>'"]/g, function(x) {
return reverseEntityTable[x];
@ -535,7 +541,7 @@
},
get innerHTML() {
if (typeof this._innerHTML === "undefined") {
this._innerHTML = encodeHTML(this._textContent || "");
this._innerHTML = encodeTextContentHTML(this._textContent || "");
}
return this._innerHTML;
},
@ -583,7 +589,13 @@
createElement: function (tag) {
var node = new Element(tag);
return node;
}
},
createTextNode: function (text) {
var node = new Text();
node.textContent = text;
return node;
},
};
var Element = function (tag) {

@ -204,8 +204,7 @@ Readability.prototype = {
// Replace links with javascript: URIs with text content, since
// they won't work after scripts have been removed from the page.
if (href.indexOf("javascript:") === 0) {
var text = new Text();
text.textContent = link.textContent;
var text = this._doc.createTextNode(link.textContent);
link.parentNode.replaceChild(text, link);
} else {
link.setAttribute("href", toAbsoluteURI(href));

@ -218,8 +218,10 @@ describe("Test HTML escaping", function() {
// let's manipulate via textContent in order to test that it alters
// the innerHTML correctly.
txtNode.textContent = txtNode.textContent + " ";
expect("<p>" + txtNode.innerHTML + "</p>").eql(baseStr.replace("</p>", " </p>"));
expect("<p>" + p.innerHTML + "</p>").eql(baseStr.replace("</p>", " </p>"));
txtNode.textContent = txtNode.textContent.trim();
var expectedHTML = baseStr.replace("&quot;", '"').replace("&apos;", "'");
expect("<p>" + txtNode.innerHTML + "</p>").eql(expectedHTML);
expect("<p>" + p.innerHTML + "</p>").eql(expectedHTML);
});

@ -64,7 +64,7 @@ I am a rather elderly man. The nature of my avocations for the last thirty
<p>My chambers were up stairs at No.--Wall-street. At one end they looked
upon the white wall of the interior of a spacious sky-light shaft, penetrating
the building from top to bottom. This view might have been considered rather
tame than otherwise, deficient in what landscape painters call &quot;life.&quot;
tame than otherwise, deficient in what landscape painters call "life."
But if so, the view from the other end of my chambers offered, at least,
a contrast, if nothing more. In that direction my windows commanded an
unobstructed view of a lofty brick wall,black by age and everlasting shade;
@ -289,8 +289,8 @@ I am a rather elderly man. The nature of my avocations for the last thirty
<p>In this very attitude did I sit when I called to him, rapidly stating
what it was I wanted him to do--namely, to examine a small paper with me.
Imagine my surprise, nay, my consternation, when without moving from his
privacy, Bartleby in a singularly mild, firm voice, replied,&quot;I would
prefer not to.&quot;</p>
privacy, Bartleby in a singularly mild, firm voice, replied,"I would prefer
not to."</p>
<p>I sat awhile in perfect silence, rallying my stunned faculties. Immediately
it occurred to me that my ears had deceived me, or Bartleby had entirely
misunderstood my meaning. I repeated my request in the clearest tone I
@ -561,7 +561,7 @@ I am a rather elderly man. The nature of my avocations for the last thirty
brush; on a chair, a tin basin, with soap and a ragged towel; in a newspaper
a few crumbs of ginger-nuts and a morsel of cheese. Yet, thought I, it
is evident enough that Bartleby has been making his home here, keeping
bachelor&apos;s hallall by himself. Immediately then the thought came sweeping
bachelor's hallall by himself. Immediately then the thought came sweeping
across me, What miserable friendlessness and loneliness are here revealed!
His poverty is great; but his solitude, how horrible! Think of it. Of a
Sunday, Wall-street is deserted as Petra; and every night of every day
@ -646,7 +646,7 @@ I am a rather elderly man. The nature of my avocations for the last thirty
to ask you to do any thing you would prefer not to do--I simply wish to
speak to you."</p>
<p>Upon this he noiselessly slid into view.</p>
<p>"Will you tell me, Bartleby, where you were born?&quot;</p>
<p>"Will you tell me, Bartleby, where you were born?"</p>
<p>"I would prefer not to."</p>
<p>"Will you tell me <i>anything </i>about yourself?"</p>
<p>"I would prefer not to."</p>
@ -685,8 +685,7 @@ I am a rather elderly man. The nature of my avocations for the last thirty
the stubborn mule! What is it, sir, pray, that he <i>prefers</i> not to do
now?"</p>
<p>Bartleby moved not a limb.</p>
<p>&quot;Mr. Nippers,&quot; said I, &quot;I&apos;d prefer that you would
withdraw for the present.&quot;</p>
<p>"Mr. Nippers," said I, "I'd prefer that you would withdraw for the present."</p>
<p>Somehow, of late I had got into the way of involuntary using this word
"prefer" upon all sorts of not exactly suitable occasions. And I trembled
to think that my contact with the scrivener had already and seriously affected
@ -772,9 +771,9 @@ I am a rather elderly man. The nature of my avocations for the last thirty
<p>Now I had an unbounded confidence in this man's common honesty. He had
frequently restored to me six pences and shillings carelessly dropped upon
the floor, for I am apt to be very reckless in such shirt-button affairs.
The proceeding then which followed will not be deemed extraordinary. "Bartleby,&quot;
said I, &quot;I owe you twelve dollars on account; here are thirty-two;
the odd twenty are yours.--Will you take it? and I handed the bills towards
The proceeding then which followed will not be deemed extraordinary. "Bartleby,"
said I, "I owe you twelve dollars on account; here are thirty-two; the
odd twenty are yours.--Will you take it? and I handed the bills towards
him.</p>
<p>But he made no motion.</p>
<p>"I will leave them here then," putting them under a weight on the table.
@ -1056,9 +1055,9 @@ I am a rather elderly man. The nature of my avocations for the last thirty
<p>"What are you doing here, Bartleby?" said I.</p>
<p>"Sitting upon the banister," he mildly replied.</p>
<p>I motioned him into the lawyer's room, who then left us.</p>
<p>"Bartleby,&quot; said I, "are you aware that you are the cause of great
tribulation to me, by persisting in occupying the entry after being dismissed
from the office?"</p>
<p>"Bartleby," said I, "are you aware that you are the cause of great tribulation
to me, by persisting in occupying the entry after being dismissed from
the office?"</p>
<p>No answer.</p>
<p>"Now one of two things must take place. Either you must do something or
something must be done to you. Now what sort of business would you like
@ -1186,10 +1185,10 @@ I am a rather elderly man. The nature of my avocations for the last thirty
<p>"I think he is a little deranged," said I, sadly.</p>
<p>"Deranged? deranged is it? Well now, upon my word, I thought that friend
of yourn was a gentleman forger; they are always pale and genteel-like,
them forgers. I can&apos;t help pity &apos;em--can't help it, sir. Did
you know Monroe Edwards?" he added touchingly, and paused. Then, laying
his hand pityingly on my shoulder, sighed, "he died of consumption at Sing-Sing.
so you weren't acquainted with Monroe?"</p>
them forgers. I can't help pity 'em--can't help it, sir. Did you know Monroe
Edwards?" he added touchingly, and paused. Then, laying his hand pityingly
on my shoulder, sighed, "he died of consumption at Sing-Sing. so you weren't
acquainted with Monroe?"</p>
<p>"No, I was never socially acquainted with any forgers. But I cannot stop
longer. Look to my friend yonder. You will not lose by it. I will see you
again."</p>

@ -1860,4 +1860,4 @@ body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt;}
</center>
</body>
</html>
</html>

Loading…
Cancel
Save