Skip to content

Commit e42c4fd

Browse files
authored
only replace first basePath occurrence in dump source href (#57458)
1 parent 500c837 commit e42c4fd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Foundation\Concerns;
44

5+
use Illuminate\Support\Str;
56
use Throwable;
67

78
trait ResolvesDumpSource
@@ -169,7 +170,7 @@ protected function resolveSourceHref($file, $line)
169170
: ($this->editorHrefs[$editor['name'] ?? $editor] ?? sprintf('%s://open?file={file}&line={line}', $editor['name'] ?? $editor));
170171

171172
if ($basePath = $editor['base_path'] ?? false) {
172-
$file = str_replace($this->basePath, $basePath, $file);
173+
$file = Str::replaceStart($this->basePath, $basePath, $file);
173174
}
174175

175176
return str_replace(

tests/Foundation/Http/HtmlDumperTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ public function testHref()
254254
'vscode://file//my-docker-work-directory/app/my-file:1',
255255
$href,
256256
);
257+
258+
// When base path appears elsewhere in the file path
259+
$config->set('app.editor', ['name' => 'vscode', 'base_path' => '/my-docker-work-directory']);
260+
$href = (fn () => $this->resolveSourceHref(
261+
'/my-work-directory/storage/my-work-directory/my-file',
262+
10,
263+
))->call($dumper);
264+
$this->assertSame(
265+
'vscode://file//my-docker-work-directory/storage/my-work-directory/my-file:10',
266+
$href,
267+
);
257268
}
258269

259270
protected function dump($value)

0 commit comments

Comments
 (0)