Skip to content

Commit

Permalink
Merge pull request #214 from willdean/develop
Browse files Browse the repository at this point in the history
Avoid CssMinifier stripping spaces that are followed by colons
  • Loading branch information
Shazwazza authored Nov 6, 2024
2 parents 3ad9bfe + a11e46e commit 3436b51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Smidge.Core/FileProcessors/CssMinifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private void ExecuteCssMin()
{
case ' ': //body.Replace(" ", String.Empty);
case '{': //body = body.Replace(" {", "{");
case ':': //body = body.Replace(" {", "{");
case '\n': //body = body.Replace(" \n", "\n");
case '\r': //body = body.Replace(" \r", "\r");
case '\t': //body = body.Replace(" \t", "\t");
Expand Down Expand Up @@ -300,4 +299,4 @@ private void Put(int c)
// return Task.FromResult(input);
// }
//}
}
}
20 changes: 19 additions & 1 deletion test/Smidge.Tests/CssMinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,23 @@ public async Task Strip_Comments()

}

[Fact]
public async Task CssMin_Ensure_Spaces_Not_Stripped_From_Complex_Selectors()
{
//refer to this: https://github.com/Shazwazza/Smidge/issues/139
//The problem is stripping spaces which are followed by a colon - that's not OK this type of selector

var css = ".prose :where([class~=lead]):not(:where([class~=not-prose] *)){}";

var minifier = new CssMinifier();
using (var bc = BundleContext.CreateEmpty("1"))
{
var fileProcessContext = new FileProcessContext(css, Mock.Of<IWebFile>(), bc);
await minifier.ProcessAsync(fileProcessContext, ctx => Task.FromResult(0));

Assert.Equal(css, fileProcessContext.FileContent);
}
}

}
}
}

0 comments on commit 3436b51

Please sign in to comment.