@@ -83,6 +83,7 @@ import {
8383} from '../utils'
8484import type { Logger } from '../logger'
8585import { cleanUrl , isWindows , slash } from '../../shared/utils'
86+ import { NULL_BYTE_PLACEHOLDER } from '../../shared/constants'
8687import { createBackCompatIdResolver } from '../idResolver'
8788import type { ResolveIdFn } from '../idResolver'
8889import { PartialEnvironment } from '../baseEnvironment'
@@ -3160,10 +3161,9 @@ async function compileLightningCSS(
31603161) : ReturnType < typeof compileCSS > {
31613162 const { config } = environment
31623163 const deps = new Set < string > ( )
3163- // Relative path is needed to get stable hash when using CSS modules
3164- const filename = cleanUrl ( path . relative ( config . root , id ) )
3165- const toAbsolute = ( filePath : string ) =>
3166- path . isAbsolute ( filePath ) ? filePath : path . join ( config . root , filePath )
3164+ // replace null byte as lightningcss treats that as a string terminator
3165+ // https://github.com/parcel-bundler/lightningcss/issues/874
3166+ const filename = id . replace ( '\0' , NULL_BYTE_PLACEHOLDER )
31673167
31683168 let res : LightningCssTransformAttributeResult | LightningCssTransformResult
31693169 try {
@@ -3180,16 +3180,14 @@ async function compileLightningCSS(
31803180 ) . bundleAsync ( {
31813181 ...config . css . lightningcss ,
31823182 filename,
3183+ // projectRoot is needed to get stable hash when using CSS modules
3184+ projectRoot : config . root ,
31833185 resolver : {
31843186 read ( filePath ) {
31853187 if ( filePath === filename ) {
31863188 return src
31873189 }
3188- // This happens with html-proxy (#13776)
3189- if ( ! filePath . endsWith ( '.css' ) ) {
3190- return src
3191- }
3192- return fs . readFileSync ( toAbsolute ( filePath ) , 'utf-8' )
3190+ return fs . readFileSync ( filePath , 'utf-8' )
31933191 } ,
31943192 async resolve ( id , from ) {
31953193 const publicFile = checkPublicFile (
@@ -3202,7 +3200,7 @@ async function compileLightningCSS(
32023200
32033201 const resolved = await getAtImportResolvers (
32043202 environment . getTopLevelConfig ( ) ,
3205- ) . css ( environment , id , toAbsolute ( from ) )
3203+ ) . css ( environment , id , from )
32063204
32073205 if ( resolved ) {
32083206 deps . add ( resolved )
@@ -3224,7 +3222,7 @@ async function compileLightningCSS(
32243222 } catch ( e ) {
32253223 e . message = `[lightningcss] ${ e . message } `
32263224 e . loc = {
3227- file : toAbsolute ( e . fileName ) ,
3225+ file : e . fileName . replace ( NULL_BYTE_PLACEHOLDER , '\0' ) ,
32283226 line : e . loc . line ,
32293227 column : e . loc . column - 1 , // 1-based
32303228 }
@@ -3242,7 +3240,10 @@ async function compileLightningCSS(
32423240 if ( skipUrlReplacer ( dep . url ) ) {
32433241 replaceUrl = dep . url
32443242 } else if ( urlReplacer ) {
3245- replaceUrl = await urlReplacer ( dep . url , toAbsolute ( dep . loc . filePath ) )
3243+ replaceUrl = await urlReplacer (
3244+ dep . url ,
3245+ dep . loc . filePath . replace ( NULL_BYTE_PLACEHOLDER , '\0' ) ,
3246+ )
32463247 } else {
32473248 replaceUrl = dep . url
32483249 }
0 commit comments