openresty / openresty/test-nginx

`more_headers` with `eval` filter will throw warning of 'uninitialized value $key'

Open
#51 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
456
Forks
112
PR merge metrics
No merged PRs in 30d

Description

this is my t directory layout:

└── t
    └── Var
        ├── Conf.pm
    ├── test.t

the content of Conf.pm

package Var::Conf;

use Exporter qw(import);

our @EXPORT_OK = qw(Headers);


our $Headers = q{
Cookie: sessionId=0ca3eafb0a8ffc8146ac0609897d6a24; controlId=7cf98c6218e2f4154ff74b69a6fa3f5d
};

1;

the content of test.t

use Test::Nginx::Socket::Lua no_plan;
use Cwd qw(cwd abs_path);

use File::Basename qw(dirname);
use lib dirname(abs_path $0);
use Var::Conf qw(Headers);

$ENV{TEST_NGINX_CODE_PWD} = cwd();

#repeat_each(2);

no_long_string();

run_tests();

__DATA__

=== TEST 1: basic resty test
--- http_config
    init_worker_by_lua_block {
        print("init")
    }

--- config
    location = /t {
        echo ok;
    }

--- more_headers eval: $Var::Conf::Headers

--- request
GET /t
--- response_body
ok

then , run the cmd: prove t/test.t
will give the warning of uninitialized value

Use of uninitialized value $key in lc at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 301, <DATA> line 1.
Use of uninitialized value $key in concatenation (.) or string at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 306, <DATA> line 1.
t/test.t .. ok   
All tests successful.
Files=1, Tests=2,  0 wallclock secs ( 0.02 usr  0.01 sys +  0.18 cusr  0.04 csys =  0.25 CPU)
Result: PASS

if i replace the --- more_headers eval: $Var::Conf::Headers in test.t, with

--- more_headers
    Cookie: sessionId=0ca3eafb0a8ffc8146ac0609897d6a24; controlId=7cf98c6218e2f4154ff74b69a6fa3f5d

the warning message gone.

============================================
OS: Ubuntu 14.04
Test:Nginx v0.25

perl -v give me this:

This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi

nginx -v output:

nginx version: openresty/1.9.7.4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning with t/test.t and the eval form of the more_headers directive, then inspect Test/Nginx/Socket.pm around lines 301 and 306. Compare this with the literal more_headers case; done means the eval form processes the header without uninitialized-value warnings while the test still passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.