Skip to content

Commit b9597b2

Browse files
committed
Fix bug where star and underscore hacks interfered with validation (fixes #24)
1 parent 8476908 commit b9597b2

File tree

9 files changed

+79
-17
lines changed

9 files changed

+79
-17
lines changed

build/node-parserlib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
24+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
934+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2658,7 +2658,7 @@ Parser.prototype = function(){
26582658
prio = this._prio();
26592659

26602660
try {
2661-
this._validateProperty(property, expr);
2661+
this._validateProperty(property.text, expr);
26622662
} catch (ex) {
26632663
invalid = ex;
26642664
}

build/npm/lib/node-parserlib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
24+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
934+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2658,7 +2658,7 @@ Parser.prototype = function(){
26582658
prio = this._prio();
26592659

26602660
try {
2661-
this._validateProperty(property, expr);
2661+
this._validateProperty(property.text, expr);
26622662
} catch (ex) {
26632663
invalid = ex;
26642664
}

build/parserlib-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
24+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
2525
var parserlib = {};
2626
(function(){
2727

build/parserlib-css.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
24+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
2525
(function(){
2626
var EventTarget = parserlib.util.EventTarget,
2727
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1748,7 +1748,7 @@ Parser.prototype = function(){
17481748
prio = this._prio();
17491749

17501750
try {
1751-
this._validateProperty(property, expr);
1751+
this._validateProperty(property.text, expr);
17521752
} catch (ex) {
17531753
invalid = ex;
17541754
}

build/parserlib-tests.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,22 @@
14771477
var result = parser.parse(".foo {\n color: #fff;\n}");
14781478
},
14791479

1480+
"Test rule with star hack property": function(){
1481+
var parser = new Parser({ strict: true, starHack: true});
1482+
parser.addListener("property", function(event){
1483+
Assert.areEqual("*color", event.property.toString());
1484+
Assert.areEqual("color", event.property.text);
1485+
Assert.areEqual("#fff", event.value.toString());
1486+
Assert.areEqual(5, event.property.col, "Property column should be 5.");
1487+
Assert.areEqual(2, event.property.line, "Property line should be 2.");
1488+
Assert.areEqual(5, event.col, "Event column should be 5.");
1489+
Assert.areEqual(2, event.line, "Event line should be 2.");
1490+
Assert.areEqual(13, event.value.parts[0].col, "First part column should be 13.");
1491+
Assert.areEqual(2, event.value.parts[0].line, "First part line should be 2.");
1492+
});
1493+
var result = parser.parse(".foo {\n *color: #fff;\n}");
1494+
},
1495+
14801496
"Test rule with space after property name": function(){
14811497
var parser = new Parser({ strict: true});
14821498
parser.addListener("property", function(event){
@@ -2271,15 +2287,15 @@
22712287
ValidationTestCase.prototype = new YUITest.TestCase();
22722288

22732289
ValidationTestCase.prototype._testValidValue = function(value){
2274-
var parser = new Parser({ strict: true});
2290+
var parser = new Parser({ strict: true, starHack: true, underscoreHack: true });
22752291
parser.addListener("property", function(event){
22762292
Assert.isNull(event.invalid);
22772293
});
22782294
var result = parser.parse(".foo { " + this.property + ":" + value + "}");
22792295
};
22802296

22812297
ValidationTestCase.prototype._testInvalidValue = function(value, message){
2282-
var parser = new Parser({ strict: true});
2298+
var parser = new Parser({ strict: true, starHack: true, underscoreHack: true });
22832299
parser.addListener("property", function(event){
22842300
Assert.isNotNull(event.invalid);
22852301
Assert.areEqual(message, event.invalid.message);
@@ -2750,6 +2766,21 @@
27502766
}
27512767
}));
27522768

2769+
// Test star hack
2770+
suite.add(new ValidationTestCase({
2771+
property: "*z-index",
2772+
2773+
valid: [
2774+
"1",
2775+
"auto",
2776+
"inherit"
2777+
],
2778+
2779+
invalid: {
2780+
"foo" : "Expected (<integer> | auto | inherit) but found 'foo'."
2781+
}
2782+
}));
2783+
27532784

27542785

27552786
YUITest.TestRunner.add(suite);

build/parserlib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
24+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 2-March-2012 02:44:32 */
934+
/* Version v@VERSION@, Build time: 26-April-2012 09:26:13 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2658,7 +2658,7 @@ Parser.prototype = function(){
26582658
prio = this._prio();
26592659

26602660
try {
2661-
this._validateProperty(property, expr);
2661+
this._validateProperty(property.text, expr);
26622662
} catch (ex) {
26632663
invalid = ex;
26642664
}

src/css/Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ Parser.prototype = function(){
14581458
prio = this._prio();
14591459

14601460
try {
1461-
this._validateProperty(property, expr);
1461+
this._validateProperty(property.text, expr);
14621462
} catch (ex) {
14631463
invalid = ex;
14641464
}

tests/css/Parser.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,22 @@
14771477
var result = parser.parse(".foo {\n color: #fff;\n}");
14781478
},
14791479

1480+
"Test rule with star hack property": function(){
1481+
var parser = new Parser({ strict: true, starHack: true});
1482+
parser.addListener("property", function(event){
1483+
Assert.areEqual("*color", event.property.toString());
1484+
Assert.areEqual("color", event.property.text);
1485+
Assert.areEqual("#fff", event.value.toString());
1486+
Assert.areEqual(5, event.property.col, "Property column should be 5.");
1487+
Assert.areEqual(2, event.property.line, "Property line should be 2.");
1488+
Assert.areEqual(5, event.col, "Event column should be 5.");
1489+
Assert.areEqual(2, event.line, "Event line should be 2.");
1490+
Assert.areEqual(13, event.value.parts[0].col, "First part column should be 13.");
1491+
Assert.areEqual(2, event.value.parts[0].line, "First part line should be 2.");
1492+
});
1493+
var result = parser.parse(".foo {\n *color: #fff;\n}");
1494+
},
1495+
14801496
"Test rule with space after property name": function(){
14811497
var parser = new Parser({ strict: true});
14821498
parser.addListener("property", function(event){

tests/css/Validation.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
ValidationTestCase.prototype = new YUITest.TestCase();
3939

4040
ValidationTestCase.prototype._testValidValue = function(value){
41-
var parser = new Parser({ strict: true});
41+
var parser = new Parser({ strict: true, starHack: true, underscoreHack: true });
4242
parser.addListener("property", function(event){
4343
Assert.isNull(event.invalid);
4444
});
4545
var result = parser.parse(".foo { " + this.property + ":" + value + "}");
4646
};
4747

4848
ValidationTestCase.prototype._testInvalidValue = function(value, message){
49-
var parser = new Parser({ strict: true});
49+
var parser = new Parser({ strict: true, starHack: true, underscoreHack: true });
5050
parser.addListener("property", function(event){
5151
Assert.isNotNull(event.invalid);
5252
Assert.areEqual(message, event.invalid.message);
@@ -517,6 +517,21 @@
517517
}
518518
}));
519519

520+
// Test star hack
521+
suite.add(new ValidationTestCase({
522+
property: "*z-index",
523+
524+
valid: [
525+
"1",
526+
"auto",
527+
"inherit"
528+
],
529+
530+
invalid: {
531+
"foo" : "Expected (<integer> | auto | inherit) but found 'foo'."
532+
}
533+
}));
534+
520535

521536

522537
YUITest.TestRunner.add(suite);

0 commit comments

Comments
 (0)