Commit e003236a authored by Sergey Lyubka's avatar Sergey Lyubka

Made SSI #include file= relative to the current doc, as per spec

parent de774537
...@@ -143,8 +143,10 @@ directives are supported, `<!--#include ...>` and ...@@ -143,8 +143,10 @@ directives are supported, `<!--#include ...>` and
three path specifications: three path specifications:
<!--#include virtual="path"> Path is relative to web server root <!--#include virtual="path"> Path is relative to web server root
<!--#include file="path"> Path is relative to web server working dir <!--#include abspath="path"> Path is absolute or relative to
<!--#include "path"> Path is relative to current document web server working dir
<!--#include file="path">, Path is relative to current document
<!--#include "path">
The `include` directive may be used to include the contents of a file or the The `include` directive may be used to include the contents of a file or the
result of running a CGI script. The `exec` directive is used to execute a result of running a CGI script. The `exec` directive is used to execute a
......
...@@ -3611,11 +3611,12 @@ static void do_ssi_include(struct mg_connection *conn, const char *ssi, ...@@ -3611,11 +3611,12 @@ static void do_ssi_include(struct mg_connection *conn, const char *ssi,
// File name is relative to the webserver root // File name is relative to the webserver root
(void) mg_snprintf(conn, path, sizeof(path), "%s%c%s", (void) mg_snprintf(conn, path, sizeof(path), "%s%c%s",
conn->ctx->config[DOCUMENT_ROOT], '/', file_name); conn->ctx->config[DOCUMENT_ROOT], '/', file_name);
} else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1) { } else if (sscanf(tag, " abspath=\"%[^\"]\"", file_name) == 1) {
// File name is relative to the webserver working directory // File name is relative to the webserver working directory
// or it is absolute system path // or it is absolute system path
(void) mg_snprintf(conn, path, sizeof(path), "%s", file_name); (void) mg_snprintf(conn, path, sizeof(path), "%s", file_name);
} else if (sscanf(tag, " \"%[^\"]\"", file_name) == 1) { } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1 ||
sscanf(tag, " \"%[^\"]\"", file_name) == 1) {
// File name is relative to the currect document // File name is relative to the currect document
(void) mg_snprintf(conn, path, sizeof(path), "%s", ssi); (void) mg_snprintf(conn, path, sizeof(path), "%s", ssi);
if ((p = strrchr(path, '/')) != NULL) { if ((p = strrchr(path, '/')) != NULL) {
......
<html><pre> <html><pre>
ssi_begin ssi_begin
<!--#include file="Makefile" --> <!--#include file="../Makefile" -->
ssi_end ssi_end
</pre></html> </pre></html>
<html><pre> <html><pre>
ssi_begin ssi_begin
<!--#include file="/etc/passwd" --> <!--#include abspath="/etc/passwd" -->
ssi_end ssi_end
</pre></html> </pre></html>
<html><pre> <html><pre>
ssi_begin ssi_begin
<!--#include file="c:\boot.ini" --> <!--#include abspath="c:\boot.ini" -->
ssi_end ssi_end
</pre></html> </pre></html>
ssi_begin ssi_begin
<!--#include file="Makefile" --> <!--#include file="../Makefile" -->
ssi_end ssi_end
...@@ -403,7 +403,7 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") { ...@@ -403,7 +403,7 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") {
my $abs_path = on_windows() ? 'ssi6.shtml' : 'ssi5.shtml'; my $abs_path = on_windows() ? 'ssi6.shtml' : 'ssi5.shtml';
my $word = on_windows() ? 'boot loader' : 'root'; my $word = on_windows() ? 'boot loader' : 'root';
o("GET /$abs_path HTTP/1.0\n\n", o("GET /$abs_path HTTP/1.0\n\n",
"ssi_begin.+$word.+ssi_end", 'SSI #include file= (absolute)'); "ssi_begin.+$word.+ssi_end", 'SSI #include abspath');
o("GET /ssi7.shtml HTTP/1.0\n\n", o("GET /ssi7.shtml HTTP/1.0\n\n",
'ssi_begin.+Unit test.+ssi_end', 'SSI #include "..."'); 'ssi_begin.+Unit test.+ssi_end', 'SSI #include "..."');
o("GET /ssi8.shtml HTTP/1.0\n\n", o("GET /ssi8.shtml HTTP/1.0\n\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment