@server/next 0.28.6 → 0.28.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.28.6",
3
+ "version": "0.28.7",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
@@ -27,13 +27,13 @@ const altAttrs = {
27
27
  const isValidChild = (child) =>
28
28
  child != null && child !== false && child !== true;
29
29
 
30
- // CSS helpers
31
- const escapeCSS = (value) => String(value).replace(/[<>&"'`]/g, "\\$&");
32
-
33
30
  const minifyCss = (str) =>
34
31
  str
35
- .replace(/\s+/g, " ")
36
32
  .replace(/\/\*[\s\S]*?\*\//g, "")
33
+ .replace(/\s+/g, " ")
34
+ .replace(/\s*([{}:;,>~+])\s*/g, "$1")
35
+ .replace(/;}/g, "}")
36
+ .replace(/<\/style>/gi, "<\\/style>")
37
37
  .trim();
38
38
 
39
39
  // React element detection (safe for custom objects too)
@@ -104,9 +104,9 @@ const jsx = (tag, { children, ...props } = {}) => {
104
104
  children = raw(content);
105
105
  }
106
106
 
107
- // style: minified + escaped raw content
107
+ // style: minified raw content
108
108
  if (tag === "style" && typeof children === "string") {
109
- children = raw(minifyCss(escapeCSS(children)));
109
+ children = raw(minifyCss(children));
110
110
  }
111
111
 
112
112
  // dangerouslySetInnerHTML
@@ -299,20 +299,50 @@ describe("script tag", () => {
299
299
  describe("style tag", () => {
300
300
  it("renders style content", () => {
301
301
  expect(<style>{"body { color: red; }"}</style>).toRender(
302
- "<style>body { color: red; }</style>",
302
+ "<style>body{color:red}</style>",
303
303
  );
304
304
  });
305
305
 
306
306
  it("minifies whitespace in style content", () => {
307
307
  expect(
308
308
  <style>{"body {\n color: red;\n margin: 0;\n}"}</style>,
309
- ).toRender("<style>body { color: red; margin: 0; }</style>");
309
+ ).toRender("<style>body{color:red;margin:0}</style>");
310
310
  });
311
311
 
312
312
  it("strips CSS comments", () => {
313
313
  expect(
314
314
  <style>{"/* reset */ body { margin: 0; } /* end */"}</style>,
315
- ).toRender("<style>body { margin: 0; }</style>");
315
+ ).toRender("<style>body{margin:0}</style>");
316
+ });
317
+
318
+ it("preserves child combinator in selectors", () => {
319
+ expect(
320
+ <style>{":not(pre) > code { background: none; }"}</style>,
321
+ ).toRender("<style>:not(pre)>code{background:none}</style>");
322
+ });
323
+
324
+ it("preserves sibling combinators in selectors", () => {
325
+ expect(
326
+ <style>{"h2 + p { margin: 0; } h2 ~ p { color: red; }"}</style>,
327
+ ).toRender("<style>h2+p{margin:0}h2~p{color:red}</style>");
328
+ });
329
+
330
+ it("removes spaces around braces, colons, and semicolons", () => {
331
+ expect(
332
+ <style>{"a { color : red ; font-size : 1em ; }"}</style>,
333
+ ).toRender("<style>a{color:red;font-size:1em}</style>");
334
+ });
335
+
336
+ it("removes trailing semicolon before closing brace", () => {
337
+ expect(
338
+ <style>{"p { margin: 0; padding: 0; }"}</style>,
339
+ ).toRender("<style>p{margin:0;padding:0}</style>");
340
+ });
341
+
342
+ it("does not break </style> injection", () => {
343
+ expect(
344
+ <style>{"a { content: '</style>'; }"}</style>,
345
+ ).toRender("<style>a{content:'<\\/style>'}</style>");
316
346
  });
317
347
  });
318
348