浏览代码

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

Sergey Lyubka 12 年之前
父节点
当前提交
e003236a03
共有 7 个文件被更改,包括 12 次插入9 次删除
  1. 4 2
      UserManual.md
  2. 3 2
      mongoose.c
  3. 1 1
      test/ssi1.shtml
  4. 1 1
      test/ssi5.shtml
  5. 1 1
      test/ssi6.shtml
  6. 1 1
      test/ssi9.shtml
  7. 1 1
      test/test.pl

+ 4 - 2
UserManual.md

@@ -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 "path">          Path is relative to current document
+    <!--#include abspath="path">  Path is absolute or relative to
+                                  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

+ 3 - 2
mongoose.c

@@ -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) {

+ 1 - 1
test/ssi1.shtml

@@ -1,5 +1,5 @@
 <html><pre>
 <html><pre>
 ssi_begin
 ssi_begin
-<!--#include file="Makefile" -->
+<!--#include file="../Makefile" -->
 ssi_end
 ssi_end
 </pre></html>
 </pre></html>

+ 1 - 1
test/ssi5.shtml

@@ -1,5 +1,5 @@
 <html><pre>
 <html><pre>
 ssi_begin
 ssi_begin
-<!--#include file="/etc/passwd" -->
+<!--#include abspath="/etc/passwd" -->
 ssi_end
 ssi_end
 </pre></html>
 </pre></html>

+ 1 - 1
test/ssi6.shtml

@@ -1,5 +1,5 @@
 <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>

+ 1 - 1
test/ssi9.shtml

@@ -1,3 +1,3 @@
 ssi_begin
 ssi_begin
-<!--#include file="Makefile" -->
+<!--#include file="../Makefile" -->
 ssi_end
 ssi_end

+ 1 - 1
test/test.pl

@@ -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",