Skip to content

ElementExtensions.GetInnerText removes whitespace before span #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mattwTS opened this issue May 22, 2019 · 1 comment
Closed

ElementExtensions.GetInnerText removes whitespace before span #32

mattwTS opened this issue May 22, 2019 · 1 comment
Assignees
Milestone

Comments

@mattwTS
Copy link

mattwTS commented May 22, 2019

Bug Report

Description

The GetInnerText() extension method in v0.12.1 of AngleSharp.Css removes whitespace before a <span> element; that isn't desired behavior.

Steps to Reproduce

using AngleSharp;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;

static class Program
{
	static void Main()
	{
		var ctx = BrowsingContext.New(Configuration.Default.WithCss());
		var parser = ctx.GetService<IHtmlParser>();
		var nodeList = parser.ParseFragment("<div><div>Div with <span>a span</span> in it.</div></div>", null);
		var element = (IElement)nodeList[0];
		Console.WriteLine(element.GetInnerText());
		Console.ReadKey();
	}
}

Expected behavior: Outputs "Div with a span in it.".

In all of Firefox, Chrome, Edge, and IE, pasting var wrapper = document.createElement("div"); wrapper.innerHTML = "<div>Div with <span>a span</span> in it.</div>"; wrapper.innerText into the developer console produces this output.

Actual behavior: Outputs "Div witha span in it."

Environment details: .NET Framework v4.6.2

Possible Solution

The problem appears to lie at the end of ProcessText. I'm not sure I fully understand the intent there, it appears to remove a single space after the last non-whitespace character of a text node with trailing white-space. I think that might not be correct when the subsequent node is an inline element, the text node is at the end of an inline element, or if the style for the text node had white-space pre or pre-wrap.

@FlorianRappl
Copy link
Contributor

Landed in devel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants