Skip to content

Commit

Permalink
fix cascaded detached rulsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Feb 10, 2019
1 parent bcaf74d commit 6ba6bd4
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/com/inet/lib/less/LessLookAheadReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Scanner;

/**
* A reader with some special look ahead reading.
Expand All @@ -41,7 +42,7 @@ class LessLookAheadReader extends LessObject implements Closeable {

private final StringBuilder cache = new StringBuilder();

private StringReader blockMarkReader;
private StringReader cache2;

private final boolean isReference, isMultiple;

Expand Down Expand Up @@ -71,12 +72,12 @@ class LessLookAheadReader extends LessObject implements Closeable {
* if an I/O error occur
*/
private int readCharBlockMarker() throws IOException {
if( blockMarkReader != null ) {
int ch = blockMarkReader.read();
if( cache2 != null ) {
int ch = cache2.read();
if( ch != -1 ) {
return ch;
}
blockMarkReader = null;
cache2 = null;
}
return reader.read();
}
Expand All @@ -90,7 +91,15 @@ private int readCharBlockMarker() throws IOException {
*/
int nextBlockMarker() throws LessException {
if( cachePos < cache.length() ) {
blockMarkReader = new StringReader( cache.substring( cachePos ) );
String str = cache.substring( cachePos );
if( cache2 != null ) { // occur with detached rulset inside another detached ruleset
try (Scanner scanner = new Scanner( cache2 ).useDelimiter( "\\A" )) {
if( scanner.hasNext() ) {
str = scanner.next() + str;
}
}
}
cache2 = new StringReader( str );
}
cache.setLength( cachePos = 0 );
int parenthesis = 0;
Expand Down Expand Up @@ -149,13 +158,21 @@ int nextBlockMarker() throws LessException {
}
}
if( !isBlock ) {
int braces = 1;
do {
ch = readCharBlockMarker();
if( ch < 0 ) {
throw createException( "Unrecognized input: '" + cache.toString().trim() + "'" );
switch( ch ) {
case -1:
throw createException( "Unrecognized input: '" + cache.toString().trim() + "'" );
case '}':
braces--;
break;
case '{':
braces++;
break;
}
cache.append( (char)ch );
} while( ch != '}' );
} while( braces > 0 );
break;
}
//$FALL-THROUGH$
Expand Down

0 comments on commit 6ba6bd4

Please sign in to comment.