Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/astro/src/vite-plugin-config-alias/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export default function configAliasVitePlugin({

const replaceAliases = (match: string, importId: string) => {
if (!importId) return match;
// Skip data URIs — they are inline content, not file paths.
if (importId.startsWith('data:')) return match;

const resolved = resolveWithAlias(importId, configAlias);
if (resolved) {
Expand Down
28 changes: 28 additions & 0 deletions packages/astro/test/alias-css-url-data-uri.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { type Fixture, loadFixture } from './test-utils.ts';

// Regression test for https://github.com/withastro/astro/issues/17293
// CSS url() with data URIs should not crash when tsconfig baseUrl is set.
describe('CSS url() with data URIs and tsconfig baseUrl', () => {
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/alias-css-url-data-uri/',
});
await fixture.build();
});

it('preserves data URIs in url() without ENAMETOOLONG crash', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);

const styleTag = $('style').html() || '';
assert.ok(
styleTag.includes('data:image/svg+xml;base64,'),
'CSS should preserve the data URI',
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { defineConfig } from 'astro/config';
export default defineConfig({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "@test/alias-css-url-data-uri"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

---

<html><body><h1>Hello</h1></body></html>

<style>
.icon {
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMiI+PHBhdGggZD0iTTEyIDJMMiA3bDEwIDUgMTAtNS0xMC01eiIvPjwvc3ZnPg==');
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"baseUrl": "."
}
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading