Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
Update code
  • Loading branch information
JonathanMagnan committed Nov 25, 2019
1 parent 127d21a commit 5f82294
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/HtmlAgilityPack.Shared/HtmlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(' ');

Expand Down
22 changes: 14 additions & 8 deletions src/HtmlAgilityPack.Shared/HtmlWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
}
}
Expand Down Expand Up @@ -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.
}
}
Expand Down Expand Up @@ -2546,4 +2552,4 @@ public HtmlDocument LoadFromBrowser(string url, Func<object, bool> isBrowserScri
}

}
#endif
#endif

0 comments on commit 5f82294

Please sign in to comment.