Skip to content

Commit

Permalink
Fix crash on CSS @import with variable name
Browse files Browse the repository at this point in the history
Follows-up a1173e7 (I8220cd808f), which introduced this crash by
evaluating import nodes much earlier but lacking a try-catch for cases
that don't need to be compiled by LESS. We missed this in CI because
the upstream urls.less is disabled pending T353147.

Follows-up e7ed93f (Iddd8e41137), which regressed path compilation
such that it outputs filesystem paths where URLs are expected.

Bug: T361035
Change-Id: I302e7527c2b72eebbc26f85fa0ff2f54b5988abc
  • Loading branch information
Hannah Okwelum authored and Krinkle committed Apr 8, 2024
1 parent 0a022bd commit 9105597
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/Less/ImportVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public function visitImport( $importNode, &$visitDeeper ) {
}

public function processImportNode( $importNode, $env, &$importParent ) {
$inlineCSS = $importNode->options['inline'];
$evaldImportNode = $inlineCSS = $importNode->options['inline'];

// TODO: We might need upstream's try-catch here
// try { … } catch ( e ) { importNode.css = true; importNode.error = e; }
$evaldImportNode = $importNode->compileForImport( $env );
try {
$evaldImportNode = $importNode->compileForImport( $env );
} catch ( Exception $e ) {
$importNode->css = true;
}

if ( $evaldImportNode && ( !$evaldImportNode->css || $inlineCSS ) ) {

Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function compilePath( $env ) {
$pathValue = $path->value;
// Add the base path if the import is relative
if ( $pathValue && Less_Environment::isPathRelative( $pathValue ) ) {
$path->value = $rootpath . $pathValue;
$path->value = $this->currentFileInfo['uri_root'] . $pathValue;
}
}
$path->value = Less_Environment::normalizePath( $path->value );
Expand Down
1 change: 1 addition & 0 deletions test/Fixtures/less.php/css/T361035-variable-name.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "test.css";
5 changes: 5 additions & 0 deletions test/Fixtures/less.php/less/T361035-variable-name.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.add_an_import(@file_to_import) {
@import "@{file_to_import}";
}

.add_an_import("test.css");

0 comments on commit 9105597

Please sign in to comment.