~spuul/nginx/trunk

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/037-gsub.t

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-02-15 03:05:42 UTC
  • mfrom: (4.3.10 sid)
  • Revision ID: package-import@ubuntu.com-20140215030542-71ubtowl24vf7nfn
Tags: 1.4.5-1ubuntu1
* Resynchronise with Debian (LP: #1280511).  Remaining changes:
  - debian/patches/ubuntu-branding.patch:
    + Add Ubuntu branding to server_tokens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim:set ft= ts=4 sw=4 et fdm=marker:
2
2
use lib 'lib';
3
 
use Test::Nginx::Socket;
 
3
use Test::Nginx::Socket::Lua;
4
4
 
5
5
#worker_connections(1014);
6
6
#master_on();
9
9
 
10
10
repeat_each(2);
11
11
 
12
 
plan tests => repeat_each() * (blocks() * 2 + 10);
 
12
plan tests => repeat_each() * (blocks() * 2 + 14);
13
13
 
14
14
#no_diff();
15
15
no_long_string();
425
425
--- request
426
426
GET /t
427
427
--- response_body_like chop
428
 
error: pcre_exec\(\) failed: -10 on "你.*?" using "你好"
429
 
 
430
 
--- no_error_log
431
 
[error]
 
428
error: pcre_exec\(\) failed: -10
 
429
 
 
430
--- no_error_log
 
431
[error]
 
432
 
 
433
 
 
434
 
 
435
=== TEST 21: UTF-8 mode without UTF-8 sequence checks
 
436
--- config
 
437
    location /re {
 
438
        content_by_lua '
 
439
            local s, n, err = ngx.re.gsub("你好", ".", "a", "U")
 
440
            if s then
 
441
                ngx.say("s: ", s)
 
442
            end
 
443
        ';
 
444
    }
 
445
--- stap
 
446
probe process("$LIBPCRE_PATH").function("pcre_compile") {
 
447
    printf("compile opts: %x\n", $options)
 
448
}
 
449
 
 
450
probe process("$LIBPCRE_PATH").function("pcre_exec") {
 
451
    printf("exec opts: %x\n", $options)
 
452
}
 
453
 
 
454
--- stap_out
 
455
compile opts: 800
 
456
exec opts: 2000
 
457
exec opts: 2000
 
458
exec opts: 2000
 
459
 
 
460
--- request
 
461
    GET /re
 
462
--- response_body
 
463
s: aa
 
464
--- no_error_log
 
465
[error]
 
466
 
 
467
 
 
468
 
 
469
=== TEST 22: UTF-8 mode with UTF-8 sequence checks
 
470
--- config
 
471
    location /re {
 
472
        content_by_lua '
 
473
            local s, n, err = ngx.re.gsub("你好", ".", "a", "u")
 
474
            if s then
 
475
                ngx.say("s: ", s)
 
476
            end
 
477
        ';
 
478
    }
 
479
--- stap
 
480
probe process("$LIBPCRE_PATH").function("pcre_compile") {
 
481
    printf("compile opts: %x\n", $options)
 
482
}
 
483
 
 
484
probe process("$LIBPCRE_PATH").function("pcre_exec") {
 
485
    printf("exec opts: %x\n", $options)
 
486
}
 
487
 
 
488
--- stap_out
 
489
compile opts: 800
 
490
exec opts: 0
 
491
exec opts: 0
 
492
exec opts: 0
 
493
 
 
494
--- request
 
495
    GET /re
 
496
--- response_body
 
497
s: aa
 
498
--- no_error_log
 
499
[error]
 
500
 
 
501
 
 
502
 
 
503
=== TEST 23: just hit match limit
 
504
--- http_config
 
505
    lua_regex_match_limit 5600;
 
506
--- config
 
507
    location /re {
 
508
        content_by_lua_file html/a.lua;
 
509
    }
 
510
 
 
511
--- user_files
 
512
>>> a.lua
 
513
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
 
514
 
 
515
s = string.rep([[ABCDEFG]], 10)
 
516
 
 
517
local start = ngx.now()
 
518
 
 
519
local res, cnt, err = ngx.re.gsub(s, re, "", "o")
 
520
 
 
521
--[[
 
522
ngx.update_time()
 
523
local elapsed = ngx.now() - start
 
524
ngx.say(elapsed, " sec elapsed.")
 
525
]]
 
526
 
 
527
if err then
 
528
    ngx.say("error: ", err)
 
529
    return
 
530
end
 
531
ngx.say("gsub: ", cnt)
 
532
 
 
533
--- request
 
534
    GET /re
 
535
--- response_body
 
536
error: pcre_exec() failed: -8
 
537
 
 
538
 
 
539
 
 
540
=== TEST 24: just not hit match limit
 
541
--- http_config
 
542
    lua_regex_match_limit 5700;
 
543
--- config
 
544
    location /re {
 
545
        content_by_lua_file html/a.lua;
 
546
    }
 
547
 
 
548
--- user_files
 
549
>>> a.lua
 
550
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
 
551
 
 
552
local s = string.rep([[ABCDEFG]], 10)
 
553
 
 
554
local start = ngx.now()
 
555
 
 
556
local res, cnt, err = ngx.re.gsub(s, re, "", "o")
 
557
 
 
558
--[[
 
559
ngx.update_time()
 
560
local elapsed = ngx.now() - start
 
561
ngx.say(elapsed, " sec elapsed.")
 
562
]]
 
563
 
 
564
if err then
 
565
    ngx.say("error: ", err)
 
566
    return
 
567
end
 
568
ngx.say("gsub: ", cnt)
 
569
 
 
570
--- request
 
571
    GET /re
 
572
--- response_body
 
573
gsub: 0
 
574
--- timeout: 10
432
575