Skip to content

Commit c6218a2

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "Fix "PHP Warning: Undefined array key currentUri" when using @import (inline)"
2 parents f7ca4db + 9f19aa8 commit c6218a2

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ insert_final_newline = true
1010
[test/phpunit/ParserTest.php]
1111
trim_trailing_whitespace = false
1212

13+
[test/**/*.map]
14+
insert_final_newline = false
15+
1316
# Markdown:
1417
# - Editors should not change leading spaces to tabs (e.g. multi-line list items)
1518
# YAML:

lib/Less/Output/Mapped.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public function add( $chunk, $fileInfo = null, $index = 0, $mapLines = null ) {
6363
$sourceLines = [];
6464
$sourceColumns = ' ';
6565

66-
if ( $fileInfo ) {
67-
66+
if ( isset( $fileInfo['currentUri'] ) ) {
6867
$url = $fileInfo['currentUri'];
6968

7069
if ( isset( $this->contentsMap[$url] ) ) {

lib/Less/SourceMap/Generator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ public function addMapping( $generatedLine, $generatedColumn, $originalLine, $or
204204
'generated_column' => $generatedColumn,
205205
'original_line' => $originalLine,
206206
'original_column' => $originalColumn,
207-
'source_file' => $fileInfo['currentUri']
207+
'source_file' => $fileInfo['currentUri'] ?? null
208208
];
209209

210-
$this->sources[$fileInfo['currentUri']] = $fileInfo['filename'];
210+
if ( isset( $fileInfo['currentUri'] ) ) {
211+
$this->sources[$fileInfo['currentUri']] = $fileInfo['filename'];
212+
}
211213
}
212214

213215
/**

test/Fixtures/less.php/css/T380641-sourcemap-import-inline.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import (inline, css) url("imports/a.less");

test/phpunit/MapTest.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,34 @@ public function testMap() {
77
$expectedFile = self::$fixturesDir . '/bootstrap3-sourcemap/expected/bootstrap.map';
88
$mapDestination = self::$cacheDir . '/bootstrap.map';
99

10-
$options['sourceMap'] = true;
11-
$options['sourceMapWriteTo'] = $mapDestination;
12-
$options['sourceMapURL'] = '/';
13-
$options['sourceMapBasepath'] = dirname( dirname( $lessFile ) );
14-
$options['math'] = "always";
10+
$parser = new Less_Parser( [
11+
'sourceMap' => true,
12+
'sourceMapURL' => '/',
13+
'sourceMapBasepath' => dirname( dirname( $lessFile ) ),
14+
'sourceMapWriteTo' => $mapDestination,
15+
'math' => 'always',
16+
] );
17+
$parser->parseFile( $lessFile );
18+
$parser->getCss();
19+
20+
$expected = file_get_contents( $expectedFile );
21+
$generated = file_get_contents( $mapDestination );
22+
$this->assertEquals( $expected, $generated );
23+
}
24+
25+
public function testImportInline() {
26+
$lessFile = self::$fixturesDir . '/less.php/less/T380641-sourcemap-import-inline.less';
27+
$expectedFile = self::$fixturesDir . '/less.php/css/T380641-sourcemap-import-inline.map';
28+
$mapDestination = self::$cacheDir . '/import-inline.map';
1529

16-
$parser = new Less_Parser( $options );
30+
$parser = new Less_Parser( [
31+
'sourceMap' => true,
32+
'sourceMapURL' => '/',
33+
'sourceMapBasepath' => dirname( $lessFile ),
34+
'sourceMapWriteTo' => $mapDestination,
35+
] );
1736
$parser->parseFile( $lessFile );
18-
$css = $parser->getCss();
37+
$parser->getCss();
1938

2039
$expected = file_get_contents( $expectedFile );
2140
$generated = file_get_contents( $mapDestination );

0 commit comments

Comments
 (0)