Skip to content

Commit

Permalink
Fix bug with indexing style attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jamietre committed Apr 25, 2013
1 parent 7887764 commit f068951
Show file tree
Hide file tree
Showing 23 changed files with 477 additions and 135 deletions.
2 changes: 1 addition & 1 deletion source/CsQuery.Tests/Core/Attributes/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void ClassStyleAttributes()
Assert.AreEqual("badge2",badge2.Classes.First());

var styleOnly = dom["#hidden-div > :first-child"][0];
var style= "width:100;height:200";
var style= "width: 100; height: 200;";

Assert.IsTrue(styleOnly.HasAttributes);
Assert.IsFalse(styleOnly.HasClasses);
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery.Tests/Core/Css/Css.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void RemoveStyle()
Assert.AreEqual("height: 10; display: none;", dom["div"][0]["style"]);

dom["div"].CssSet(new { display = null as object });
Assert.AreEqual("height: 10", dom["div"][0]["style"]);
Assert.AreEqual("height: 10;", dom["div"][0]["style"]);
}

protected class StylesClass
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery.Tests/Core/WebIO/QueryRemoteServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace CsQuery.Tests.Core.WebIO
public class _WebIO_QueryRemoteServer : CsQueryTest
{
private KeyValuePair<string,string>[] urls = new KeyValuePair<string,string>[] {
new KeyValuePair<string,string>("https://github.com/jamietre/csquery","img[alt='GitHub']"),
new KeyValuePair<string,string>("https://github.com/jamietre/csquery","div.repo-desc-homepage"),
new KeyValuePair<string,string>("http://www.cnn.com/","#cnn_hdr")
};

Expand Down
1 change: 1 addition & 0 deletions source/CsQuery.Tests/Csquery.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
</Compile>
<Compile Include="Core\Selectors\Extensions.cs" />
<Compile Include="Implementation\ChildNodeList.cs" />
<Compile Include="Implementation\CssStyleDeclaration.cs" />
<Compile Include="Implementation\IndexQueue.cs" />
<Compile Include="Implementation\RangeSortedDictionary.cs" />
<Compile Include="Miscellaneous\Miscellaneous2.cs" />
Expand Down
45 changes: 45 additions & 0 deletions source/CsQuery.Tests/Implementation/CssStyleDeclaration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
using Description = NUnit.Framework.DescriptionAttribute;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
using CsQuery.Implementation;

namespace CsQuery.Tests.Core.Implementation
{
[TestFixture, TestClass]
public class CssStyleDeclaration_ : CsQueryTest
{

[Test, TestMethod]
public void StyleInIndex()
{
CQ test = "<div></div><div id=target style='width: 10px' ></div>";

var target = test["div[style]"];

Assert.AreEqual(1, target.Length);
Assert.AreEqual("10px", target.Css("width"));

target.Css("width", null);

target = test["div[style]"];
Assert.AreEqual(1, target.Length);
Assert.AreEqual("", target.Attr("style"));

target[0].RemoveAttribute("style");

Assert.AreEqual(null, target.Attr("style"));
target = test["div[style]"];
Assert.AreEqual(0, target.Length);

}

}
}

19 changes: 19 additions & 0 deletions source/CsQuery.Tests/Miscellaneous/Miscellaneous2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ namespace CsQuery.Tests.Miscellaneous
[TestFixture, TestClass]
public class Reindex: CsQueryTest
{
[Test, TestMethod]
public void Issue99()
{
//var dom = TestDom("jquery-unit-index");
CQ dom = @"<html><body><span style=''>1lb14.4oz</span></body></html>";
var res = dom["span:visible"];
Assert.IsTrue(true);



}
[Test, TestMethod]
public void Issue97()
{
var dom = CQ.Create("<?xml version=\"1.0\"?><rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel><atom:link href=\"http://www.cnbc.com/id/100003241/device/rss/rss.html\" rel=\"self\" type=\"application/rss+xml\" /><title>Markets Headlines</title><description><![CDATA[]]></description><fakeLink>http://www.cnbc.com/id/100003241</fakeLink><pubDate>Fri, 22 Mar 2013 06:29 GMT</pubDate><lastBuildDate>Fri, 22 Mar 2013 06:29 GMT</lastBuildDate><language>en-us</language><ttl>60</ttl><item><title>Euro Rises on Hopes for Last-Minute Cyprus Deal</title><description><![CDATA[The euro rose Friday on optimism Cyprus will be able to cobble together a last-minute deal.]]></description><fakeLink>http://www.cnbc.com/id/100579967</fakeLink><pubDate>Fri, 22 Mar 2013 21:02 GMT</pubDate><guid isPermaLink=\"false\">guid_100579967</guid> </item> <item><title>US Oil Gains Over $1 as Equities Rise</title><description><![CDATA[Brent crude edged higher on Friday while U.S. crude futures jumped more than $1 per barrel, sending the spread between the two contracts to the narrowest level since July. \r\n ]]></description><fakeLink>http://www.cnbc.com/id/100580094</fakeLink><pubDate>Fri, 22 Mar 2013 20:23 GMT</pubDate><guid isPermaLink=\"false\">guid_100580094</guid> </item> <item><title>US Bonds Near Flat on Cyprus Uncertainty</title><description><![CDATA[Prices for U.S. Treasurys traded flat on Friday as a bailout for Cyprus remained in doubt going into the weekend. ]]></description><fakeLink>http://www.cnbc.com/id/100580561</fakeLink><pubDate>Fri, 22 Mar 2013 20:17 GMT</pubDate><guid isPermaLink=\"false\">guid_100580561</guid> </item> <item><title>Gold Down as Cyprus Fears Ease, Notches Weekly Gain</title><description><![CDATA[Gold fell as investors took profits a day after the precious metal hit a one-month high.]]></description><fakeLink>http://www.cnbc.com/id/100580130</fakeLink><pubDate>Fri, 22 Mar 2013 19:55 GMT</pubDate><guid isPermaLink=\"false\">guid_100580130</guid> </item> <item><title>Asia Falls 2% This Week on Cyprus; China Rallies</title><description><![CDATA[Festering concerns of a banking collapse in Cyprus led to a sell-off in most Asian markets on Friday, resulting in a 2 percent weekly loss. However, mainland shares outshone to post a weekly gain of 2 percent after Thursday&#039;s Flash PMI data.\r\n ]]></description><fakeLink>http://www.cnbc.com/id/100579945</fakeLink><pubDate>Fri, 22 Mar 2013 08:00 GMT</pubDate><guid isPermaLink=\"false\">guid_100579945</guid> </item> <item><title>Yen Surges as Investors Worry Over Cyprus Turmoil</title><description><![CDATA[The yen surged against the dollar and euro on Thursday amid fears of a financial meltdown in Cyprus.]]></description><fakeLink>http://www.cnbc.com/id/100575330</fakeLink><pubDate>Thu, 21 Mar 2013 20:58 GMT</pubDate><guid isPermaLink=\"false\">guid_100575330</guid> </item> <item><title>Treasurys Climb as Cyprus Scrambles for Aid</title><description><![CDATA[Prices for U.S. Treasurys rose on Thursday as bailout plans for Cyprus remained in disarray.]]></description><fakeLink>http://www.cnbc.com/id/100575882</fakeLink><pubDate>Thu, 21 Mar 2013 20:23 GMT</pubDate><guid isPermaLink=\"false\">guid_100575882</guid> </item> <item><title>Oil Battered by Cyprus Angst, Dour German Figures</title><description><![CDATA[Crude oil was pushed lower by fears of further turmoil in the euro zone, as Cyprus scrambled to avoid bankruptcy.]]></description><fakeLink>http://www.cnbc.com/id/100575400</fakeLink><pubDate>Thu, 21 Mar 2013 19:45 GMT</pubDate><guid isPermaLink=\"false\">guid_100575400</guid> </item> <item><title>Gold Hits Near 1-Month High on Cyprus Debt Fears</title><description><![CDATA[Gold rose to a near one-month high, as safe-haven buying emerged after the European Union gave Cyprus an ultimatum.]]></description><fakeLink>http://www.cnbc.com/id/100575458</fakeLink><pubDate>Thu, 21 Mar 2013 18:44 GMT</pubDate><guid isPermaLink=\"false\">guid_100575458</guid> </item> <item><title>European Shares Close Lower on Cyprus Fears</title><description><![CDATA[European shares closed lower.]]></description><fakeLink>http://www.cnbc.com/id/100575843</fakeLink><pubDate>Thu, 21 Mar 2013 16:35 GMT</pubDate><guid isPermaLink=\"false\">guid_100575843</guid> </item> <item><title>Futures Narrowly Mixed After Jobless Claims</title><description><![CDATA[Stock index futures hovered around the flatline Thursday following the weekly jobless claims report, while uncertainty in Cyprus kept investors on edge. ]]></description><fakeLink>http://www.cnbc.com/id/100576605</fakeLink><pubDate>Thu, 21 Mar 2013 13:16 GMT</pubDate><guid isPermaLink=\"false\">guid_100576605</guid> </item> <item><title>Asia Turns Mixed; Nikkei Scales 4 1/2-Year Peak</title><description><![CDATA[A pick-up in Chinese manufacturing and expectations of monetary easing drove North Asian shares higher but political tensions in Seoul and Sydney put a cap on further regional gains.\r\n ]]></description><fakeLink>http://www.cnbc.com/id/100574983</fakeLink><pubDate>Thu, 21 Mar 2013 08:06 GMT</pubDate><guid isPermaLink=\"false\">guid_100574983</guid> </item> <item><title>Can Investors Take Comfort in Latest China PMI?</title><description><![CDATA[With recent Chinese economic data offering mixed signals over the health of the world&#039;s second largest economy, should investors take comfort from the HSBC&#039;s flash manufacturing PMI for March?]]></description><fakeLink>http://www.cnbc.com/id/100575757</fakeLink><pubDate>Thu, 21 Mar 2013 04:07 GMT</pubDate><guid isPermaLink=\"false\">guid_100575757</guid> </item> <item><title>The UK Budget Did No Favor to the Pound</title><description><![CDATA[Chancellor George Osborne disappointed those who wanted to see a big change in the Bank of England&#039;s mandate. The pound strengthened a bit as a result, but those who are waiting to see it weaken will not be disappointed.]]></description><fakeLink>http://www.cnbc.com/id/100575565</fakeLink><pubDate>Thu, 21 Mar 2013 03:55 GMT</pubDate><guid isPermaLink=\"false\">guid_100575565</guid> </item> <item><title>Traders to Pick Over Data, With Fed in Mind</title><description><![CDATA[Housing and jobs data will get a close look from traders Thursday, as they continue to dissect the comments from the Fed.]]></description><fakeLink>http://www.cnbc.com/id/100574651</fakeLink><pubDate>Thu, 21 Mar 2013 00:25 GMT</pubDate><guid isPermaLink=\"false\">guid_100574651</guid> </item> <item><title>Dollar Rallies as Fed Says No Change to Easy Money</title><description><![CDATA[The US dollar rallied after a decision by the Federal Reserve to continue its aggressive monetary easing.]]></description><fakeLink>http://www.cnbc.com/id/100570564</fakeLink><pubDate>Wed, 20 Mar 2013 21:16 GMT</pubDate><guid isPermaLink=\"false\">guid_100570564</guid> </item> <item><title>Gold Holds Losses After Fed Decision</title><description><![CDATA[Gold eased from the previous session&#039;s three-week high on Wednesday, reflecting some investor optimism that the crisis in Cyprus may not spread further in the euro zone.\r\n ]]></description><fakeLink>http://www.cnbc.com/id/100570568</fakeLink><pubDate>Wed, 20 Mar 2013 20:36 GMT</pubDate><guid isPermaLink=\"false\">guid_100570568</guid> </item> <item><title>Stocks End Higher After Fed Decision, Dow Hits New Intraday High</title><description><![CDATA[Stocks finished higher Wednesday, wiping out most of the past week&#039;s losses and with the Dow touching a new intraday high. ]]></description><fakeLink>http://www.cnbc.com/id/100572871</fakeLink><pubDate>Wed, 20 Mar 2013 20:23 GMT</pubDate><guid isPermaLink=\"false\">guid_100572871</guid> </item> <item><title>Brent Crude Oil Rises to $108 From 3-Month Low</title><description><![CDATA[Brent crude oil rose above $108 a barrel, recovering from a three-month low/]]></description><fakeLink>http://www.cnbc.com/id/100570567</fakeLink><pubDate>Wed, 20 Mar 2013 20:05 GMT</pubDate><guid isPermaLink=\"false\">guid_100570567</guid> </item> <item><title>US Bonds Stay Heavy After Fed Decision</title><description><![CDATA[U.S. bonds were mired in the red after the Federal Reserve held firm on its monetary policy.]]></description><fakeLink>http://www.cnbc.com/id/100572535</fakeLink><pubDate>Wed, 20 Mar 2013 19:21 GMT</pubDate><guid isPermaLink=\"false\">guid_100572535</guid> </item> <item><title>Market Shakes Off Cyprus Jitters</title><description><![CDATA[Even as the euro zone stands firm, markets have embraced the view that Cyprus will strike a deal.\r\n ]]></description><fakeLink>http://www.cnbc.com/id/100573847</fakeLink><pubDate>Wed, 20 Mar 2013 17:12 GMT</pubDate><guid isPermaLink=\"false\">guid_100573847</guid> </item> <item><title>European Shares End Mixed as Investors Continue to Watch Cyprus</title><description><![CDATA[European shares pared their earlier gains to close narrowly mixed Wednesday. ]]></description><fakeLink>http://www.cnbc.com/id/100571158</fakeLink><pubDate>Wed, 20 Mar 2013 16:35 GMT</pubDate><guid isPermaLink=\"false\">guid_100571158</guid> </item> <item><title>More Bond Investors Bet on US Rate Rise</title><description><![CDATA[U.S. bond investors are seeking new ways to hedge against the risk of a sharp rise in interest rates, the FT reports.]]></description><fakeLink>http://www.cnbc.com/id/100573190</fakeLink><pubDate>Wed, 20 Mar 2013 15:05 GMT</pubDate><guid isPermaLink=\"false\">guid_100573190</guid> </item> <item><title>Cyprus's Plan B Spooks Asia; China Shrugs It Off</title><description><![CDATA[Asian stocks were under pressure on Wednesday as concerns rose if a bailout deal was still possible for Cyprus while Greater Chinese shares ignored the news to outperform the market as attention turned to domestic issues.\r\n ]]></description><fakeLink>http://www.cnbc.com/id/100570537</fakeLink><pubDate>Wed, 20 Mar 2013 08:10 GMT</pubDate><guid isPermaLink=\"false\">guid_100570537</guid> </item> <item><title>Warning! China Stocks May See Double-Digit Drop </title><description><![CDATA[Chinese stocks are down over 6 percent in the past month. But be warned, the worst is far from over.]]></description><fakeLink>http://www.cnbc.com/id/100570888</fakeLink><pubDate>Wed, 20 Mar 2013 03:46 GMT</pubDate><guid isPermaLink=\"false\">guid_100570888</guid> </item> <item><title>Dovish Fed Seen Keeping Lid on Market Worry</title><description><![CDATA[With Cyprus creating a new wave of worry, markets will be looking to the Fed Wednesday to keep a steady hand on the tiller.]]></description><fakeLink>http://www.cnbc.com/id/100569902</fakeLink><pubDate>Wed, 20 Mar 2013 00:12 GMT</pubDate><guid isPermaLink=\"false\">guid_100569902</guid> </item> <item><title>Euro Nears Four-Month Low on Turmoil in Cyprus </title><description><![CDATA[The euro dropped near a four-month low vs. the US dollar as uncertainty about Cyprus stoked fears about the currency. ]]></description><fakeLink>http://www.cnbc.com/id/100565748</fakeLink><pubDate>Tue, 19 Mar 2013 21:02 GMT</pubDate><guid isPermaLink=\"false\">guid_100565748</guid> </item> <item><title>US Treasurys Climb on Cyprus Worries</title><description><![CDATA[U.S. Treasurys prices climbed on Tuesday as a plan in Cyprus to tax bank accounts to help pay for a bailout unraveled, creating uncertainty about the island country&#039;s financial future and reviving fears about the stability of the euro zone. \r\n ]]></description><fakeLink>http://www.cnbc.com/id/100566307</fakeLink><pubDate>Tue, 19 Mar 2013 20:26 GMT</pubDate><guid isPermaLink=\"false\">guid_100566307</guid> </item> <item><title>Don't Count Cyprus Out of the Euro Just Yet: Traders</title><description><![CDATA[Uncertainty about Cyprus set markets on edge, but they are far from pricing in the tiny country&#039;s exit from the euro.]]></description><fakeLink>http://www.cnbc.com/id/100569669</fakeLink><pubDate>Tue, 19 Mar 2013 20:22 GMT</pubDate><guid isPermaLink=\"false\">guid_100569669</guid> </item> <item><title>Gold Extends Gains as Safety Investment Amid Cyprus Vote</title><description><![CDATA[Gold reversed earlier losses, hitting a 2-1/2 week high above $1,615 an ounce on renewed flight-to-safety investment.]]></description><fakeLink>http://www.cnbc.com/id/100565956</fakeLink><pubDate>Tue, 19 Mar 2013 19:44 GMT</pubDate><guid isPermaLink=\"false\">guid_100565956</guid> </item> </channel> </rss>");
Assert.IsTrue(true);

}

//[Test, TestMethod]
//public void XmlProb()
//{
Expand Down
5 changes: 2 additions & 3 deletions source/CsQuery/CQ_jQuery/Attr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public string Attr(string name)
case "class":
return el.ClassName;
case "style":
string st = el.Style.ToString();
return st == "" ? null : st;
return el.Style.ToString();
default:
if (el.TryGetAttribute(name, out value))
{
Expand Down Expand Up @@ -299,7 +298,7 @@ public CQ RemoveAttr(string name)
e.ClassName = "";
break;
case "style":
e.Style.Clear();
e.Style = null;
break;
default:
e.RemoveAttribute(name);
Expand Down
7 changes: 4 additions & 3 deletions source/CsQuery/CsQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
<Compile Include="Dom\Implementation\HtmlElements\HTMLLabelElement.cs" />
<Compile Include="Dom\Implementation\NodeEventArgs.cs" />
<Compile Include="Dom\Implementation\StyleSheet.cs" />
<Compile Include="Dom\IReadOnlyCollection.cs" />
<Compile Include="Implementation\IReadOnlyDictionary.cs" />
<Compile Include="Implementation\IReadOnlyCollection.cs" />
<Compile Include="Dom\HtmlElements\IHTMLFormElement.cs" />
<Compile Include="Dom\HtmlElements\IHTMLLabelElement.cs" />
<Compile Include="Dom\enumRelLink.cs" />
Expand Down Expand Up @@ -219,7 +220,7 @@
<Compile Include="Dom\IDomObjectT.cs" />
<Compile Include="Dom\HtmlElements\IHTMLOptionsCollection.cs" />
<Compile Include="Dom\Implementation\AttributeCollection.cs" />
<Compile Include="Dom\IReadOnlyList.cs" />
<Compile Include="Implementation\IReadOnlyList.cs" />
<Compile Include="Engine\CharacterEqualityComparer.cs" />
<Compile Include="Engine\PseudoClassSelectors\enumQuotingRule.cs" />
<Compile Include="Engine\PseudoClassSelectors\Other\Regex.cs" />
Expand Down Expand Up @@ -537,7 +538,7 @@ xcopy $(TargetDir)CsQuery.xml $(SolutionDir)..\Distribution /Y
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_ConfigurationName="Any" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_UpdateFileVersion="False" />
<UserProperties BuildVersion_UpdateFileVersion="False" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_ConfigurationName="Any" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UseGlobalSettings="False" />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/Dom/IDomObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface IDomObject : IDomNode, IComparable<IDomObject>
/// An object encapsulating the Styles associated with this element.
/// </summary>

CSSStyleDeclaration Style { get; }
CSSStyleDeclaration Style { get; set; }

/// <summary>
/// gets and sets the value of the class attribute of the specified element.
Expand Down
1 change: 1 addition & 0 deletions source/CsQuery/Dom/INodeListT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using CsQuery.Implementation;

namespace CsQuery
{
Expand Down
8 changes: 4 additions & 4 deletions source/CsQuery/Dom/Implementation/CSSStyleChangedArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public class CSSStyleChangedArgs : EventArgs
/// Constructor.
/// </summary>
///
/// <param name="hasStyles">
/// <param name="hasStyleAttribute">
/// A value indicating whether this object has styles following the change.
/// </param>

public CSSStyleChangedArgs(bool hasStyles)
public CSSStyleChangedArgs(bool hasStyleAttribute)
{
HasStyles = hasStyles;
HasStyleAttribute = hasStyleAttribute;
}
/// <summary>
/// Gets a value indicating whether this object has styles following the change.
/// </summary>

public bool HasStyles
public bool HasStyleAttribute
{
get;
protected set;
Expand Down
Loading

0 comments on commit f068951

Please sign in to comment.