From 9c396eeceae6549653a66f06f87762bd46140bb2 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sat, 25 Feb 2017 17:02:22 +0100 Subject: [PATCH] Fix #34 (slash handling of font property values) caused by regression from #32 --- src/com/inet/lib/less/LessParser.java | 11 +++-------- src/com/inet/lib/less/Operation.java | 10 +++++++++- test/com/inet/lib/less/samples/general/import.css | 11 ++++++----- .../inet/lib/less/samples/general/importOptional.css | 11 ++++++----- test/com/inet/lib/less/samples/general/slash.css | 11 ++++++----- test/com/inet/lib/less/samples/general/slash.less | 1 + .../lib/less/samples/less_org_tests/less/css-3.css | 2 +- .../samples/less_org_tests/less/url-args/urls.css | 4 ++-- .../lib/less/samples/less_org_tests/less/urls.css | 4 ++-- 9 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/com/inet/lib/less/LessParser.java b/src/com/inet/lib/less/LessParser.java index 704aa6c6..bb6b1f97 100644 --- a/src/com/inet/lib/less/LessParser.java +++ b/src/com/inet/lib/less/LessParser.java @@ -790,14 +790,6 @@ private Expression parseExpression( char leftOperator ) { } switch( ch ) { case '/': - if( strictMath && nesting == 0 ) { - if( wasWhite ) { - builder.append( ' ' ); - wasWhite = false; - } - builder.append( ch ); - continue LOOP; - } if( comment( null ) ) { continue LOOP; } @@ -846,6 +838,9 @@ private Expression parseExpression( char leftOperator ) { } } left = concat( left, ch, parseExpression( ch ) ); + if( strictMath && nesting == 0 && ch == '/' ) { + ((Operation)left).setDataType( Expression.STRING ); + } break; case ':': // Key value parameter like @color:#abc if( left == null ) { diff --git a/src/com/inet/lib/less/Operation.java b/src/com/inet/lib/less/Operation.java index adf80a5b..a11c3c08 100644 --- a/src/com/inet/lib/less/Operation.java +++ b/src/com/inet/lib/less/Operation.java @@ -174,6 +174,14 @@ public int getDataType( CssFormatter formatter ) { return type; } + /** + * Inject a data type from parser + * @param type the type + */ + void setDataType( int type ) { + this.type = type; + } + /** * Get the highest data type of different operands * @param formatter current formatter @@ -232,7 +240,7 @@ public void appendTo( CssFormatter formatter ) { case '/': for( int i = 0; i < operands.size(); i++ ) { if( i > 0 ) { - formatter.append( ' ' ).append( operator ).append( ' ' ); + formatter.append( operator ); } operands.get( i ).appendTo( formatter ); } diff --git a/test/com/inet/lib/less/samples/general/import.css b/test/com/inet/lib/less/samples/general/import.css index 46ade3a4..70f7f639 100644 --- a/test/com/inet/lib/less/samples/general/import.css +++ b/test/com/inet/lib/less/samples/general/import.css @@ -3,15 +3,16 @@ b: "b"; } .values .slash { + font: 1.5/2; a: 1.5; b: 1.5; - e: a / b; - f: a / b; - g: a / b; - h: a / b; + e: a/b; + f: a/b; + g: a/b; + h: a/b; font: 3/2; } .values .slash2 { - background: url("img.jpg") center / 100px; + background: url("img.jpg") center/100px; background: url(abc/img.jpg); } diff --git a/test/com/inet/lib/less/samples/general/importOptional.css b/test/com/inet/lib/less/samples/general/importOptional.css index 6995c342..c2695811 100644 --- a/test/com/inet/lib/less/samples/general/importOptional.css +++ b/test/com/inet/lib/less/samples/general/importOptional.css @@ -1,13 +1,14 @@ .slash { + font: 1.5/2; a: 1.5; b: 1.5; - e: a / b; - f: a / b; - g: a / b; - h: a / b; + e: a/b; + f: a/b; + g: a/b; + h: a/b; font: 3/2; } .slash2 { - background: url("img.jpg") center / 100px; + background: url("img.jpg") center/100px; background: url(abc/img.jpg); } diff --git a/test/com/inet/lib/less/samples/general/slash.css b/test/com/inet/lib/less/samples/general/slash.css index 6995c342..c2695811 100644 --- a/test/com/inet/lib/less/samples/general/slash.css +++ b/test/com/inet/lib/less/samples/general/slash.css @@ -1,13 +1,14 @@ .slash { + font: 1.5/2; a: 1.5; b: 1.5; - e: a / b; - f: a / b; - g: a / b; - h: a / b; + e: a/b; + f: a/b; + g: a/b; + h: a/b; font: 3/2; } .slash2 { - background: url("img.jpg") center / 100px; + background: url("img.jpg") center/100px; background: url(abc/img.jpg); } diff --git a/test/com/inet/lib/less/samples/general/slash.less b/test/com/inet/lib/less/samples/general/slash.less index 8d12b418..7c23299d 100644 --- a/test/com/inet/lib/less/samples/general/slash.less +++ b/test/com/inet/lib/less/samples/general/slash.less @@ -1,6 +1,7 @@ // comment .slash { @a: 3 / 2; + font:@a/2; a: @a; b: 3 / 2; e: a / b; diff --git a/test/com/inet/lib/less/samples/less_org_tests/less/css-3.css b/test/com/inet/lib/less/samples/less_org_tests/less/css-3.css index d2d2cf85..7438e963 100644 --- a/test/com/inet/lib/less/samples/less_org_tests/less/css-3.css +++ b/test/com/inet/lib/less/samples/less_org_tests/less/css-3.css @@ -127,5 +127,5 @@ body ^^ .shadow { display: done; } #issue2066 { - background: url('/images/icon-team.svg') 0 0 / contain; + background: url('/images/icon-team.svg') 0 0/contain; } diff --git a/test/com/inet/lib/less/samples/less_org_tests/less/url-args/urls.css b/test/com/inet/lib/less/samples/less_org_tests/less/url-args/urls.css index 4282de6b..40e5c14d 100644 --- a/test/com/inet/lib/less/samples/less_org_tests/less/url-args/urls.css +++ b/test/com/inet/lib/less/samples/less_org_tests/less/url-args/urls.css @@ -4,8 +4,8 @@ } #shorthands { background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px; - background: url("img.jpg") center / 100px; - background: #fff url(image.png) center / 1px 100px repeat-x scroll content-box padding-box; + background: url("img.jpg") center/100px; + background: #fff url(image.png) center/1px 100px repeat-x scroll content-box padding-box; } #misc { background-image: url(images/image.jpg); diff --git a/test/com/inet/lib/less/samples/less_org_tests/less/urls.css b/test/com/inet/lib/less/samples/less_org_tests/less/urls.css index 8f25aae1..8bf20b28 100644 --- a/test/com/inet/lib/less/samples/less_org_tests/less/urls.css +++ b/test/com/inet/lib/less/samples/less_org_tests/less/urls.css @@ -7,8 +7,8 @@ } #shorthands { background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px; - background: url("img.jpg") center / 100px; - background: #fff url(image.png) center / 1px 100px repeat-x scroll content-box padding-box; + background: url("img.jpg") center/100px; + background: #fff url(image.png) center/1px 100px repeat-x scroll content-box padding-box; } #misc { background-image: url(images/image.jpg);