Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

The selector engine doesn't support the HEX escaped characters #22

Merged
merged 8 commits into from
Commits on Jun 27, 2012
  1. @Vitallium
Commits on Jun 29, 2012
  1. @Vitallium

    Merge remote-tracking branch 'jamietre/master'

    Vitallium authored
    Conflicts:
    	source/CsQuery/Dom/Implementation/DomElement.cs
Commits on Jul 10, 2012
  1. @Vitallium
Commits on Jul 12, 2012
  1. @Vitallium
Commits on Jul 16, 2012
  1. @Vitallium
Commits on Jul 17, 2012
  1. @Vitallium

    Added CSS selector validation.

    Vitallium authored
    Maybe not to use try-catch.
Commits on Jul 18, 2012
  1. @Vitallium
  2. @Vitallium

    Revert "Added CSS selector validation."

    Vitallium authored
    This reverts commit edae94e.
This page is out of date. Refresh to see the latest.
View
18 source/CsQuery.Tests/Csharp/Selectors/MiscellaneousSelectors.cs
@@ -132,6 +132,24 @@ public override void FixtureSetUp()
Dom = TestDom("TestHtml");
}
+ [Test, TestMethod]
+ public void HexWith6DigitsEscapedSelector()
+ {
+ string html = "<div id=\"B&W?\"><p>test</p></div>";
+ var dom = CsQuery.CQ.CreateFragment(html);
+ var result = dom.Select("#B\\000026W\\3F");
+ Assert.Greater(result.Length, 0);
+ }
+
+ [Test, TestMethod]
+ public void HexWith2DigitsEscapedSelector()
+ {
+ string html = "<div id=\"B&W?\"><p>test</p></div>";
+ var dom = CsQuery.CQ.CreateFragment(html);
+ var result = dom.Select("#B\\26 W\\3F");
+ Assert.Greater(result.Length, 0);
+ }
+
protected string WriteDOMObject(IDomElement obj)
{
string result = "";
View
25 source/CsQuery/StringScanner/Patterns/EscapedString.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Globalization;
using CsQuery.StringScanner.Implementation;
namespace CsQuery.StringScanner.Patterns
@@ -37,6 +38,30 @@ public override bool Validate()
{
if (Escaped)
{
+ // process unicode char code point, if presented
+ int tempIndex = index;
+ StringBuilder sb = new StringBuilder();
+ while (Source[tempIndex] != ' ')
+ {
+ sb.Append(Source[tempIndex]);
+
+ if (tempIndex == Source.Length - 1 || // end of string?
+ tempIndex - index == 5) // only 6 hexadecimal digits are allowed
+ break;
+
+ tempIndex++;
+ }
+
+ if (sb.Length == 2 || sb.Length == 6)
+ {
+ int value = 0;
+ if (Int32.TryParse(sb.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
+ {
+ character = (char)value;
+ index = tempIndex;
+ }
+ }
+
Escaped = false;
}
else
Something went wrong with that request. Please try again.