diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs index 69f2529d..9e89dfc7 100644 --- a/src/HtmlAgilityPack.Shared/HtmlNode.cs +++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text; using System.Xml; @@ -2275,8 +2276,9 @@ public void AddClass(string name, bool throwError) if (!IsEmpty(classAttributes)) { foreach (HtmlAttribute att in classAttributes) - { - if (att.Value.Equals(name) || att.Value.Contains(name)) + { + // Check class solo, check class in First with other class, check Class no first. + if (att.Value != null && att.Value.Split(' ').ToList().Any(x => x.Equals(name))) { if (throwError) { @@ -2357,7 +2359,7 @@ public void RemoveClass(string name, bool throwError) { Attributes.Remove(att); } - else if (att.Value.Contains(name)) + else if (att.Value != null && att.Value.Split(' ').ToList().Any(x => x.Equals(name))) { string[] classNames = att.Value.Split(' '); diff --git a/src/HtmlAgilityPack.Shared/HtmlWeb.cs b/src/HtmlAgilityPack.Shared/HtmlWeb.cs index fea6b111..acadbdff 100644 --- a/src/HtmlAgilityPack.Shared/HtmlWeb.cs +++ b/src/HtmlAgilityPack.Shared/HtmlWeb.cs @@ -3,7 +3,7 @@ // Forum & Issues: https://github.com/zzzprojects/html-agility-pack // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved. #if !METRO @@ -1677,10 +1677,16 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc bool html = IsHtmlContent(resp.ContentType); bool isUnknown = string.IsNullOrEmpty(resp.ContentType); - Encoding respenc = !string.IsNullOrEmpty(html ? resp.CharacterSet : resp.ContentEncoding) - ? Encoding.GetEncoding(html ? resp.CharacterSet : resp.ContentEncoding) - : null; - if (OverrideEncoding != null) + // keep old code because logic on ReadDocumentEncoding(HtmlNode node), now use resp.CharacterSet here. + // for futur maybe harmonise. + //Encoding respenc = !string.IsNullOrEmpty(resp.ContentEncoding) + // ? Encoding.GetEncoding(resp.ContentEncoding) + // : null; + + Encoding respenc = !string.IsNullOrEmpty(html ? resp.CharacterSet : resp.ContentEncoding) + ? Encoding.GetEncoding(html ? resp.CharacterSet : resp.ContentEncoding) + : null; + if (OverrideEncoding != null) respenc = OverrideEncoding; if (CaptureRedirect) @@ -1774,7 +1780,7 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc } catch { - // ThatÂ’s fine, the content type was unknown so probably not HTML + // That’s fine, the content type was unknown so probably not HTML // Perhaps trying to figure if the content contains some HTML before would be a better idea. } } @@ -2000,7 +2006,7 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc } catch { - // ThatÂ’s fine, the content type was unknown so probably not HTML + // That’s fine, the content type was unknown so probably not HTML // Perhaps trying to figure if the content contains some HTML before would be a better idea. } } @@ -2546,4 +2552,4 @@ public HtmlDocument LoadFromBrowser(string url, Func isBrowserScri } } -#endif +#endif \ No newline at end of file