Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The content within block is being attempted to be included as a file. #57

Open
snouker opened this issue Dec 6, 2023 · 5 comments
Open
Labels

Comments

@snouker
Copy link

snouker commented Dec 6, 2023

I have a file defining some blocks, such as

{-head-}<br>
<h1>....</h1>
<br>
<br>{-head-}

When I use template.render("some.html"), an error occurs:

20xx/xx/xx xx:xx:xx [error] 217324#217324: *10239 open() "/path/to/templates/<br>
<h1>....</h1>
<br>
<br>" failed (2: No such file or directory), other unimportant information.

I spent some time reading code, and identified the issue at

c[j+2] = '"]=include[=['

Deleting it will result in the blocks content not being processed!

I added a functionlocal function plain(v, c) return template.process_string(v, c or context) end at line 413 and replace line 584 withc[j+2] = '"]=plain[=[', and the issue disappeared.

I'm not sure this change is necessary anymore.

@bungle
Copy link
Owner

bungle commented Dec 20, 2023

@snouker, is it possible to give a full example on how to reproduce this?

@snouker
Copy link
Author

snouker commented Dec 20, 2023

@bungle
Yes,like this(Some private information has been replaced):

#nginx.conf

worker_processes 1;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type text/html;

    error_log logs/error.log debug;#the ngx.location.capture gives a error,but I like debug
    lua_code_cache off; #make error occured in every request

    server {
        listen 80;
        server_name localhost;
        root html;

        set $template_location /view;

        location /view {
            internal;
            alias html/view;
        }
        location / {
            content_by_lua_block {
                local template = require("resty.template")
                template.render("test.html",{version=template._VERSION})
            }
        }
    }
}

<!-- html/view/test.html -->
{-head-}<br>
<h1>....</h1>
<br>
<br>{-head-}

<p>head block:<br />
    <pre>{* blocks.head *}</pre><!-- remove this line can occur also -->
    <pre>{* version *}</pre>
</p>

this is the error:

#logs/error.log

2023/*/* *:*:* [alert] 4724#4724: lua_code_cache is off; this will hurt performance in /path/to/openresty/conf/nginx.conf:12
2023/*/* *:*:* [error] 4726#4726: *1 open() "/path/to/openresty/html/view/<br>
<h1>....</h1>
<br>
<br>" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", subrequest: "/view/<br>
<h1>....</h1>
<br>
<br>", host: "localhost"
2023/*/* *:*:* [info] 4726#4726: *1 client 127.0.0.1 closed keepalive connection

this is the result of output:

<!-- html/view/test.html -->

<p>head block:<br />
    <pre><br>
<h1>....</h1>
<br>
<br></pre><!-- remove this line can occur also -->
    <pre>2.0</pre>
</p>

@bungle
Copy link
Owner

bungle commented Aug 20, 2024

I tried this and got:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/html
Date: Tue, 20 Aug 2024 08:05:52 GMT
Transfer-Encoding: chunked

<!-- html/view/test.html -->

<p>head block:<br />
    <pre><br>
<h1>....</h1>
<br>
<br></pre><!-- remove this line can occur also -->
    <pre>2.0</pre>
</p>

@bungle
Copy link
Owner

bungle commented Aug 20, 2024

But you are right, I also get:

2024/08/20 11:07:45 [error] 44089#0: *1 open() "./html/view/test.html" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", subrequest: "/view/test.html", host: "localhost:8123"
2024/08/20 11:07:45 [error] 44089#0: *1 open() "./html/view/<br>
<h1>....</h1>
<br>
<br>" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", subrequest: "/view/<br>
<h1>....</h1>
<br>
<br>", host: "localhost:8123"

in logs.

@bungle
Copy link
Owner

bungle commented Aug 20, 2024

Seems like a bug.

@bungle bungle added the bug label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants