diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2022-06-09 14:39:59 +0200 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2022-07-27 12:46:42 +0200 |
commit | 9b4b4925b38333b8d7795331d27db9811f43d72a (patch) | |
tree | 34213ad5c4a1db77ebdcf531e29bbb338e0a0671 | |
parent | 91ffd08d119b50d7491827aa6da83006c86076d9 (diff) | |
download | unit-9b4b4925b38333b8d7795331d27db9811f43d72a.tar.gz unit-9b4b4925b38333b8d7795331d27db9811f43d72a.tar.bz2 |
Ruby: fixed contents of SCRIPT_NAME.
Having the basename of the script pathname was incorrect. While
we don't have something more accurate, the best thing to do is to
have it empty (which should be the right thing most of the time).
This closes #715 issue on GitHub.
The bug was introduced in git commit
0032543fa65f454c471c968998190b027c1ff270
'Ruby: added the Rack environment parameter "SCRIPT_NAME".'.
Diffstat (limited to '')
-rw-r--r-- | docs/changes.xml | 6 | ||||
-rw-r--r-- | src/ruby/nxt_ruby.c | 46 | ||||
-rw-r--r-- | src/ruby/nxt_ruby.h | 1 | ||||
-rw-r--r-- | test/test_ruby_application.py | 2 |
4 files changed, 12 insertions, 43 deletions
diff --git a/docs/changes.xml b/docs/changes.xml index ae8478cd..158f98e9 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -75,6 +75,12 @@ increased the applications' startup timeout. </para> </change> +<change type="bugfix"> +<para> +force SCRIPT_NAME in Ruby to always be an empty string. +</para> +</change> + </changes> diff --git a/src/ruby/nxt_ruby.c b/src/ruby/nxt_ruby.c index 8f4afd35..4df77499 100644 --- a/src/ruby/nxt_ruby.c +++ b/src/ruby/nxt_ruby.c @@ -29,7 +29,6 @@ typedef struct { static nxt_int_t nxt_ruby_start(nxt_task_t *task, nxt_process_data_t *data); static VALUE nxt_ruby_init_basic(VALUE arg); -static VALUE nxt_ruby_script_basename(nxt_str_t *script); static VALUE nxt_ruby_hook_procs_load(VALUE path); static VALUE nxt_ruby_hook_register(VALUE arg); @@ -50,7 +49,7 @@ static void *nxt_ruby_thread_create_gvl(void *rctx); static VALUE nxt_ruby_thread_func(VALUE arg); static void *nxt_ruby_unit_run(void *ctx); static void nxt_ruby_ubf(void *ctx); -static int nxt_ruby_init_threads(VALUE script, nxt_ruby_app_conf_t *c); +static int nxt_ruby_init_threads(nxt_ruby_app_conf_t *c); static void nxt_ruby_join_threads(nxt_unit_ctx_t *ctx, nxt_ruby_app_conf_t *c); @@ -261,7 +260,7 @@ static nxt_int_t nxt_ruby_start(nxt_task_t *task, nxt_process_data_t *data) { int state, rc; - VALUE res, path, script; + VALUE res, path; nxt_ruby_ctx_t ruby_ctx; nxt_unit_ctx_t *unit_ctx; nxt_unit_init_t ruby_unit_init; @@ -283,10 +282,7 @@ nxt_ruby_start(nxt_task_t *task, nxt_process_data_t *data) ruby_options(2, argv); ruby_script("NGINX_Unit"); - script = nxt_ruby_script_basename(&c->script); - ruby_ctx.env = Qnil; - ruby_ctx.script = script; ruby_ctx.io_input = Qnil; ruby_ctx.io_error = Qnil; ruby_ctx.thread = Qnil; @@ -356,7 +352,7 @@ nxt_ruby_start(nxt_task_t *task, nxt_process_data_t *data) goto fail; } - rc = nxt_ruby_init_threads(script, c); + rc = nxt_ruby_init_threads(c); if (nxt_slow_path(rc == NXT_UNIT_ERROR)) { goto fail; } @@ -425,37 +421,6 @@ fail: static VALUE -nxt_ruby_script_basename(nxt_str_t *script) -{ - size_t len; - u_char *p, *last; - - last = NULL; - p = script->start + script->length; - - while (p > script->start) { - - if (p[-1] == '/') { - last = p; - break; - } - - p--; - } - - if (last != NULL) { - len = script->length - (last - script->start); - - } else { - last = script->start; - len = script->length; - } - - return rb_str_new((const char *) last, len); -} - - -static VALUE nxt_ruby_init_basic(VALUE arg) { int state; @@ -598,7 +563,7 @@ nxt_ruby_rack_env_create(VALUE arg) rb_ary_push(version, UINT2NUM(NXT_RUBY_RACK_API_VERSION_MAJOR)); rb_ary_push(version, UINT2NUM(NXT_RUBY_RACK_API_VERSION_MINOR)); - rb_hash_aset(hash_env, rb_str_new2("SCRIPT_NAME"), rctx->script); + rb_hash_aset(hash_env, rb_str_new2("SCRIPT_NAME"), rb_str_new("", 0)); rb_hash_aset(hash_env, rb_str_new2("rack.version"), version); rb_hash_aset(hash_env, rb_str_new2("rack.input"), rctx->io_input); rb_hash_aset(hash_env, rb_str_new2("rack.errors"), rctx->io_error); @@ -1393,7 +1358,7 @@ nxt_ruby_ubf(void *ctx) static int -nxt_ruby_init_threads(VALUE script, nxt_ruby_app_conf_t *c) +nxt_ruby_init_threads(nxt_ruby_app_conf_t *c) { int state; uint32_t i; @@ -1415,7 +1380,6 @@ nxt_ruby_init_threads(VALUE script, nxt_ruby_app_conf_t *c) rctx = &nxt_ruby_ctxs[i]; rctx->env = Qnil; - rctx->script = script; rctx->io_input = Qnil; rctx->io_error = Qnil; rctx->thread = Qnil; diff --git a/src/ruby/nxt_ruby.h b/src/ruby/nxt_ruby.h index 3bdd567a..26430021 100644 --- a/src/ruby/nxt_ruby.h +++ b/src/ruby/nxt_ruby.h @@ -22,7 +22,6 @@ typedef struct { VALUE env; - VALUE script; VALUE io_input; VALUE io_error; VALUE thread; diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 95c75d47..b3e02406 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -44,7 +44,7 @@ class TestRubyApplication(TestApplicationRuby): 'Request-Method': 'POST', 'Request-Uri': '/', 'Http-Host': 'localhost', - 'Script-Name': 'config.ru', + 'Script-Name': '', 'Server-Protocol': 'HTTP/1.1', 'Custom-Header': 'blah', 'Rack-Version': '13', |