mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 01:12:13 +00:00
Bugfix from Michael Stevens: when directory names contained regex
metacharacters, Boost.Build misbehaved.
* new/path.jam
(all-parents): Don't use regex to strip path prefix, use a more robust
approach.
* test/bad_dirname.py: New test.
[SVN r18576]
This commit is contained in:
31
new/path.jam
31
new/path.jam
@@ -260,34 +260,35 @@ rule glob ( dir : patterns + )
|
||||
rule all-parents ( path : upper_limit ? : cwd ? )
|
||||
{
|
||||
cwd ?= [ pwd ] ;
|
||||
local rpath = [ root $(path) $(cwd) ] ;
|
||||
local path_ele = [ regex.split [ root $(path) $(cwd) ] "/" ] ;
|
||||
|
||||
if ! $(upper_limit) {
|
||||
upper_limit = / ;
|
||||
}
|
||||
upper_limit = [ root $(upper_limit) $(cwd) ] ;
|
||||
|
||||
# Leave only directory names below 'upper_limits'
|
||||
# Assure pruned_path[2] will have no leading '/'
|
||||
local pruned_path = [ regex.match "($(upper_limit))/*(.*)" : $(rpath) : 1 2 ] ;
|
||||
if ! $(pruned_path) {
|
||||
error "$(upper_limit) is not prefix of $(path)" ;
|
||||
}
|
||||
local upper_ele = [ regex.split [ root $(upper_limit) $(cwd) ] "/" ] ;
|
||||
|
||||
if $(pruned_path[2])
|
||||
{
|
||||
# Length of 'tokens' is equal to the number of paths to check.
|
||||
local tokens = [ regex.split $(pruned_path[2]) "/" ] ;
|
||||
|
||||
# Leave only elements in 'path_ele' below 'upper_ele'
|
||||
while $(path_ele) && $(upper_ele[1]) = $(path_ele[1]) {
|
||||
upper_ele = $(upper_ele[2-]) ;
|
||||
path_ele = $(path_ele[2-]) ;
|
||||
}
|
||||
|
||||
# All upper elements removed ?
|
||||
if ! $(upper_ele) {
|
||||
# Create the relative paths to parents, number of elements in 'path_ele'
|
||||
local result ;
|
||||
for local i in $(tokens) {
|
||||
for local i in $(path_ele) {
|
||||
path = [ parent $(path) ] ;
|
||||
result += $(path) ;
|
||||
}
|
||||
return $(result) ;
|
||||
}
|
||||
else {
|
||||
error "$(upper_limit) is not prefix of $(path)" ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Search for 'pattern' in parent directories of 'dir', up till and including
|
||||
# 'upper_limit', if it is specified, or till the filesystem root otherwise.
|
||||
|
||||
25
test/bad_dirname.py
Normal file
25
test/bad_dirname.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and
|
||||
# distribute this software is granted provided this copyright notice appears in
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
|
||||
# Regression test: when directory of project root contained regex metacharacters,
|
||||
# Boost.Build failed to work. Bug reported by Michael Stevens
|
||||
|
||||
from BoostBuild import Tester, List
|
||||
|
||||
t = Tester()
|
||||
|
||||
t.write("bad[abc]dirname/Jamfile", """
|
||||
""")
|
||||
|
||||
t.write("bad[abc]dirname/project-root.jam", """
|
||||
""")
|
||||
|
||||
t.run_build_system(subdir="bad[abc]dirname")
|
||||
|
||||
t.cleanup()
|
||||
|
||||
@@ -95,6 +95,7 @@ tests = [ "project_test1",
|
||||
"absolute_sources",
|
||||
"dependency_property",
|
||||
"custom_generator",
|
||||
"bad_dirname",
|
||||
]
|
||||
|
||||
if os.name == 'posix':
|
||||
|
||||
25
v2/test/bad_dirname.py
Normal file
25
v2/test/bad_dirname.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and
|
||||
# distribute this software is granted provided this copyright notice appears in
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
|
||||
# Regression test: when directory of project root contained regex metacharacters,
|
||||
# Boost.Build failed to work. Bug reported by Michael Stevens
|
||||
|
||||
from BoostBuild import Tester, List
|
||||
|
||||
t = Tester()
|
||||
|
||||
t.write("bad[abc]dirname/Jamfile", """
|
||||
""")
|
||||
|
||||
t.write("bad[abc]dirname/project-root.jam", """
|
||||
""")
|
||||
|
||||
t.run_build_system(subdir="bad[abc]dirname")
|
||||
|
||||
t.cleanup()
|
||||
|
||||
@@ -95,6 +95,7 @@ tests = [ "project_test1",
|
||||
"absolute_sources",
|
||||
"dependency_property",
|
||||
"custom_generator",
|
||||
"bad_dirname",
|
||||
]
|
||||
|
||||
if os.name == 'posix':
|
||||
|
||||
@@ -260,34 +260,35 @@ rule glob ( dir : patterns + )
|
||||
rule all-parents ( path : upper_limit ? : cwd ? )
|
||||
{
|
||||
cwd ?= [ pwd ] ;
|
||||
local rpath = [ root $(path) $(cwd) ] ;
|
||||
local path_ele = [ regex.split [ root $(path) $(cwd) ] "/" ] ;
|
||||
|
||||
if ! $(upper_limit) {
|
||||
upper_limit = / ;
|
||||
}
|
||||
upper_limit = [ root $(upper_limit) $(cwd) ] ;
|
||||
|
||||
# Leave only directory names below 'upper_limits'
|
||||
# Assure pruned_path[2] will have no leading '/'
|
||||
local pruned_path = [ regex.match "($(upper_limit))/*(.*)" : $(rpath) : 1 2 ] ;
|
||||
if ! $(pruned_path) {
|
||||
error "$(upper_limit) is not prefix of $(path)" ;
|
||||
}
|
||||
local upper_ele = [ regex.split [ root $(upper_limit) $(cwd) ] "/" ] ;
|
||||
|
||||
if $(pruned_path[2])
|
||||
{
|
||||
# Length of 'tokens' is equal to the number of paths to check.
|
||||
local tokens = [ regex.split $(pruned_path[2]) "/" ] ;
|
||||
|
||||
# Leave only elements in 'path_ele' below 'upper_ele'
|
||||
while $(path_ele) && $(upper_ele[1]) = $(path_ele[1]) {
|
||||
upper_ele = $(upper_ele[2-]) ;
|
||||
path_ele = $(path_ele[2-]) ;
|
||||
}
|
||||
|
||||
# All upper elements removed ?
|
||||
if ! $(upper_ele) {
|
||||
# Create the relative paths to parents, number of elements in 'path_ele'
|
||||
local result ;
|
||||
for local i in $(tokens) {
|
||||
for local i in $(path_ele) {
|
||||
path = [ parent $(path) ] ;
|
||||
result += $(path) ;
|
||||
}
|
||||
return $(result) ;
|
||||
}
|
||||
else {
|
||||
error "$(upper_limit) is not prefix of $(path)" ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Search for 'pattern' in parent directories of 'dir', up till and including
|
||||
# 'upper_limit', if it is specified, or till the filesystem root otherwise.
|
||||
|
||||
Reference in New Issue
Block a user