Kouhei Sutou
kou****@clear*****
2009年 11月 9日 (月) 17:06:34 JST
須藤です。
サポート対象なのかどうかわかっていませんが、HTTPで静的ファイ
ルにアクセスしたとき、フラグメントやクエリが付いていても該当
するファイルへアクセスできるようにするパッチです。
以下のように、フラグメントやクエリがついていても、それらを除
いたファイルにアクセスできるようになります。
URI 静的ファイル
------------------------------------------------------
/index.html -> #{admin_html_path}/index.html
/index.html#anchor -> #{admin_html_path}/index.html
/index.html?key=value -> #{admin_html_path}/index.html
diff --git a/lib/str.c b/lib/str.c
index 3be4ba7..3e67f00 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -2674,11 +2674,17 @@ grn_str_url_path_normalize(const char *path, size_t path_len, char *buf, size_t
{
char *b = buf, *be = buf + buf_len - 1;
const char *p = path, *pe = path + path_len, *pc;
+ int found_fragment_or_query = 0;
if (buf_len < 2) { return; }
while (p < pe) {
- for (pc = p; pc < pe && *pc != '/'; pc++) {}
+ for (pc = p; pc < pe && *pc != '/'; pc++) {
+ if (*pc == '?' || *pc == '#') {
+ found_fragment_or_query = 1;
+ break;
+ }
+ }
if (*p == '.') {
if (pc == p + 2 && *(p + 1) == '.') {
/* '..' */
@@ -2697,6 +2703,8 @@ grn_str_url_path_normalize(const char *path, size_t path_len, char *buf, size_t
if (be - b >= pc - p) {
memcpy(b, p, (pc - p));
b += pc - p;
+ if (found_fragment_or_query)
+ break;
p = pc;
if (*pc == '/' && be > b) {
*b++ = PATH_SEPARATOR[0];
diff --git a/src/groonga.c b/src/groonga.c
index 9f65dc4..3c8e165 100644
--- a/src/groonga.c
+++ b/src/groonga.c
@@ -193,7 +193,7 @@ put_response_header(grn_ctx *ctx, const char *p, const char *pe)
{
const char *pd = NULL;
grn_obj *head = ctx->impl->outbuf;
- for (; p < pe && *p != '?'; p++) {
+ for (; p < pe && *p != '?' && *p != '#'; p++) {
if (*p == '.') {
pd = p;
}
--
--------------------------------------------------------
各種ブラウザ向けツールバーやプラグインの開発を承ります。
また、ブラウザからICカードやカメラなどのハードウェアへ
アクセスする機能の開発も承ります。
--------------------------------------------------------
株式会社クリアコード 須藤功平 <kou****@clear*****>
Tel: 03(6231)7270 URL: http://www.clear-code.com/
--------------------------------------------------------