From 0cc8f183020e18723d83eb9175cd73c5aee27355 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Fri, 27 Jun 2025 10:54:11 -0700 Subject: [PATCH] Update post --- .../2025-06-22-test-nginx-conf-directives.md | 90 ++++++++++++++----- 1 file changed, 70 insertions(+), 20 deletions(-) diff --git a/posts/2025-06-22-test-nginx-conf-directives.md b/posts/2025-06-22-test-nginx-conf-directives.md index 07f9336..aeb214a 100644 --- a/posts/2025-06-22-test-nginx-conf-directives.md +++ b/posts/2025-06-22-test-nginx-conf-directives.md @@ -387,7 +387,7 @@ Add a spec: ```moonscript describe "https://git.domain.abc", -> - it "reverse-proxy's request to a gitea unix socket", -> + it "reverse-proxy's a subdomain request to a unix socket", -> socket = fname: "unixstreamsrvr.moon", dir: "/run/gitea", owner: "nobody" basepath = debug.getinfo(1).short_src\match"^(.*)/[^/]*$" or "." seconds = 0.1 @@ -433,29 +433,79 @@ $ make test ## Bonus!: Issues We Ran Into Just Trying To Make This Post -1. `$host$request_uri` +### `$host$request_uri` - `renderers/markdown.moon` +::: filename-for-code-block +`renderers/markdown.moon` +::: - ```moonscript - dollar_temp = "0000sitegen_markdown00dollar0000" - ``` +```moonscript +dollar_temp = "0000sitegen_markdown00dollar0000" +``` - So, when two cosmo selectors had no space between them, it was ambiguous - to which selector the numbers belonged. +So, when two cosmo selectors had no space between them, it was ambiguous +to which selector the numbers belonged. - ``` - 0000sitegen_markdown00dollar0000.10000sitegen_markdown00dollar0000.2 - ``` +``` +0000sitegen_markdown00dollar0000.10000sitegen_markdown00dollar0000.2 +``` - Solution was to change the first `0` to a letter `z`: +Solution was to change the first `0` to a letter `z`: - ``` - z000sitegen_markdown00dollar0000.1z000sitegen_markdown00dollar0000.2 - ``` - - Because `dollar_temp` is a private attribute, I had to copy every function - from the sitegen markdown renderer. Which makes my renderer a copy with - some additions. +``` +z000sitegen_markdown00dollar0000.1z000sitegen_markdown00dollar0000.2 +``` -2. `$$ct` +Because `dollar_temp` is a private attribute, I had to copy every function +from the sitegen markdown renderer. Which makes my renderer a copy with +some additions. + +::: filename-for-code-block +`spec/renderers_spec.moon` +::: + +```moonscript +import escape_cosmo, unescape_cosmo from require "renderers.markdown" + +it "escapes and unescapes adjacent cosmo selectors", -> + str = "$one$two" + escaped = escape_cosmo str + assert.same escaped, + "z000sitegen_markdown00dollar0000.1z000sitegen_markdown00dollar0000.2" + assert.same str, (unescape_cosmo escape_cosmo str) +``` + +### `$$ct` + +``` +z000sitegen_markdown00dollar0000.1 +``` + +Because `.` is not a valid character for a variable name, when this string +is syntax-highlighted, it gets split, like this: + +``` +z000sitegen_markdown00dollar0000.1 +``` + +The string is then 'unescaped', but because the string got split by the +closing `` tag, it will no longer match the pattern and the +'unescape' fails. + +The solution was to change the `.` in the dollar temp pattern to `_`, which is +a valid character in a variable name. Update the `$one$two` spec escaped +string. + +::: filename-for-code-block +`spec/renderers_spec.moon` +::: + +```moonscript +it "escapes and unescapes double dollar signs", -> + out = flatten_html render [[ +```Makefile + $$name +```]] + + assert.same [[
$$name
]], out +```