Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
f4df7a61
Commit
f4df7a61
authored
Mar 20, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PathList] Escape glob metacharacters
Closes #862
parent
2aa73d65
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
path_list.rb
lib/cocoapods/sandbox/path_list.rb
+21
-1
path_list_spec.rb
spec/unit/sandbox/path_list_spec.rb
+24
-0
No files found.
lib/cocoapods/sandbox/path_list.rb
View file @
f4df7a61
...
@@ -47,7 +47,8 @@ module Pod
...
@@ -47,7 +47,8 @@ module Pod
raise
Informative
,
"Attempt to read non existent folder `
#{
root
}
`."
raise
Informative
,
"Attempt to read non existent folder `
#{
root
}
`."
end
end
root_length
=
root
.
to_s
.
length
+
1
root_length
=
root
.
to_s
.
length
+
1
paths
=
Dir
.
glob
(
root
+
"**/*"
,
File
::
FNM_DOTMATCH
)
escaped_root
=
escape_path_for_glob
(
root
)
paths
=
Dir
.
glob
(
escaped_root
+
"**/*"
,
File
::
FNM_DOTMATCH
)
absolute_dirs
=
paths
.
select
{
|
path
|
File
.
directory?
(
path
)
}
absolute_dirs
=
paths
.
select
{
|
path
|
File
.
directory?
(
path
)
}
relative_dirs
=
absolute_dirs
.
map
{
|
p
|
p
[
root_length
..-
1
]
}
relative_dirs
=
absolute_dirs
.
map
{
|
p
|
p
[
root_length
..-
1
]
}
absolute_paths
=
paths
.
reject
{
|
p
|
p
==
"
#{
root
}
/."
||
p
==
"
#{
root
}
/.."
}
absolute_paths
=
paths
.
reject
{
|
p
|
p
==
"
#{
root
}
/."
||
p
==
"
#{
root
}
/.."
}
...
@@ -174,6 +175,25 @@ module Pod
...
@@ -174,6 +175,25 @@ module Pod
end
end
end
end
# Escapes the glob metacharacters from a given path so it can used in
# Dir#glob and similar methods.
#
# @note See CocoaPods/CocoaPods#862.
#
# @param [String, Pathname] path
# The path to escape.
#
# @return [Pathname] The escaped path.
#
def
escape_path_for_glob
(
path
)
result
=
path
.
to_s
characters_to_escape
=
[
'['
,
']'
,
'{'
,
'}'
,
'?'
,
'*'
]
characters_to_escape
.
each
do
|
character
|
result
.
gsub!
(
character
,
"
\\
#{
character
}
"
)
end
Pathname
.
new
(
result
)
end
#-----------------------------------------------------------------------#
#-----------------------------------------------------------------------#
end
end
...
...
spec/unit/sandbox/path_list_spec.rb
View file @
f4df7a61
...
@@ -38,6 +38,14 @@ module Pod
...
@@ -38,6 +38,14 @@ module Pod
dirs
.
sort
.
should
==
%w| Classes Resources Resources/sub_dir sub-dir sub-dir/sub-dir-2 |
dirs
.
sort
.
should
==
%w| Classes Resources Resources/sub_dir sub-dir sub-dir/sub-dir-2 |
end
end
it
"handles directories with glob metacharacters"
do
root
=
temporary_directory
+
'[CP] Test'
root
.
mkpath
FileUtils
.
touch
(
root
+
'Class.h'
)
@path_list
=
Sandbox
::
PathList
.
new
(
root
)
@path_list
.
files
.
should
==
[
"Class.h"
]
end
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
@@ -122,6 +130,7 @@ module Pod
...
@@ -122,6 +130,7 @@ module Pod
end
end
end
end
#--------------------------------------#
describe
"#directory?"
do
describe
"#directory?"
do
it
"expands a pattern into all the combinations of Dir#glob literals"
do
it
"expands a pattern into all the combinations of Dir#glob literals"
do
...
@@ -148,7 +157,22 @@ module Pod
...
@@ -148,7 +157,22 @@ module Pod
Classes/file.m
Classes/file.m
]
]
end
end
end
end
#--------------------------------------#
describe
"#escape_path_for_glob"
do
it
"escapes metacharacters"
do
escaped
=
@path_list
.
send
(
:escape_path_for_glob
,
'[]{}?**'
)
escaped
.
to_s
.
should
==
'\[\]\{\}\?\*\*'
end
end
#--------------------------------------#
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment