# New Ticket Created by  Kay-Uwe Huell 
# Please include the string:  [perl #39864]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39864 >


Hi parrot team,

please try attached code. Output of this is:

   [EMAIL PROTECTED]:~/work/dev/wickedWiki/trunk$ parrot 
spikes/pge_test_dir.t
   S0: '/bar/..', dir = '/foo/bar/../glork'
   1 dir: '/foo/glork'
   S0: '', dir = '/foo/glork'
   2 dir = '/foo/glork'
   3 dir = '/foo/glork'
   4 dir = '�/glork'
   5 dir = '�/glork'
   ret: dir = '�/glork'
   dir: '�/glork'

output at '4' should still be 'dir = '/foo/glork'. I compile a P6Regex 
before output of this line and after '3'. This behaviour is not expected.

Thanks,

kiwi

.sub normalizeDir
    .param string dir
    .local string pattern
    .local pmc p6regexp_compile, p6regexp, match, dotdot

    load_bytecode 'PGE.pbc'
    p6regexp_compile = compreg 'PGE::P6Regex'
    pattern = ' / \w+ / \. \. '
    p6regexp = p6regexp_compile(pattern)

  NEXT_MATCH:
    match = p6regexp(dir)
    $S0 = match
    print "S0: '"
    print $S0
    print "', dir = '"
    print dir
    print "'\n"
    if $S0 == '' goto NORMALIZED

    $P0 = getattribute match, '$.from'
    $I0 = $P0
    $P0 = getattribute match, '$.pos'
    $I1 = $P0
    $I1 -= $I0

    substr dir, $I0, $I1, ''
    print "1 dir: '"
    print dir
    print "'\n"
    goto NEXT_MATCH

  NORMALIZED:
    print "2 dir = '"
    print dir
    print "'\n"
    unless dir == '' goto VALIDATE_DIR
    dir = '.'

  VALIDATE_DIR:
    print "3 dir = '"
    print dir
    print "'\n"
    $S0 = ' \. \. '
    p6regexp = p6regexp_compile($S0)   # (*) THIS SOMEHOW SUBSTITUTES FIRST
                                       #     PART OF dir
    print "4 dir = '"
    print dir
    print "'\n"
    match = p6regexp(dir)
    print "5 dir = '"
    print dir
    print "'\n"
    $S0 = match
    unless $S0 == '' goto NO_VALID_DIR
    print "ret: dir = '"
    print dir
    print "'\n"
    .return(dir)

  NO_VALID_DIR:
    .return('')
.end

.sub main :main
    $S0 = normalizeDir('/foo/bar/../glork')
    print "dir: '"
    print $S0
    print "'\n"
.end

Reply via email to