summaryrefslogtreecommitdiffstats
path: root/web/html/pkgsubmit.php
diff options
context:
space:
mode:
authorGergely Imreh <imrehg@gmail.com>2009-01-22 03:54:05 +0100
committerLoui Chang <louipc.ist@gmail.com>2009-01-28 09:26:23 +0100
commit2568851eacd5a073aba2e105bcbf59e2fba5c6fd (patch)
treed7ca82c71e3273a82192383de68612914f19591b /web/html/pkgsubmit.php
parent24865f2a4d6d44265fe5d1b4762671cb3feb3ba9 (diff)
downloadaur-2568851eacd5a073aba2e105bcbf59e2fba5c6fd.tar.gz
aur-2568851eacd5a073aba2e105bcbf59e2fba5c6fd.tar.xz
FS#2649, FS#12645: subsititution of all variables and "eval"
All custom variables are handled during subsitution, as well as bash "eval" statements. Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web/html/pkgsubmit.php')
-rw-r--r--web/html/pkgsubmit.php37
1 files changed, 26 insertions, 11 deletions
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php
index 9e74f5fa..09f98e84 100644
--- a/web/html/pkgsubmit.php
+++ b/web/html/pkgsubmit.php
@@ -180,19 +180,34 @@ if ($_COOKIE["AURSID"]):
}
}
- # Now, run through the pkgbuild array and do any $pkgname/$pkgver
- # substituions.
- #
- # TODO: run through and do ALL substitutions, to cover custom vars
+ # Now, run through the pkgbuild array, and do "eval" and simple substituions.
if (!$error) {
- $pkgname_var = $pkgbuild["pkgname"];
- $pkgver_var = $pkgbuild["pkgver"];
- $new_pkgbuild = array();
while (list($k, $v) = each($pkgbuild)) {
- $v = str_replace('$pkgname', $pkgname_var, $v);
- $v = str_replace('${pkgname}', $pkgname_var, $v);
- $v = str_replace('$pkgver', $pkgver_var, $v);
- $v = str_replace('${pkgver}', $pkgver_var, $v);
+ if (strpos($k,'eval ') !== false) {
+ $k = preg_replace('/^eval[\s]*/', "", $k);
+ ##"eval" replacements
+ $pattern_eval = '/{\$({?)([\w]+)(}?)}/';
+ while (preg_match($pattern_eval,$v,$regs)) {
+ $pieces = explode(",",$pkgbuild["$regs[2]"]);
+ ## nongreedy matching! - preserving the order of "eval"
+ $pattern = '/([\S]*?){\$'.$regs[1].$regs[2].$regs[3].'}([\S]*)/';
+ while (preg_match($pattern,$v,$regs_replace)) {
+ $replacement = "";
+ for ($i = 0; $i < sizeof($pieces); $i++) {
+ $replacement .= $regs_replace[1].$pieces[$i].$regs_replace[2]." ";
+ }
+ $v=preg_replace($pattern, $replacement, $v, 1);
+ }
+ }
+ }
+ ##simple variable replacement
+ $pattern_var = '/\$({?)([\w]+)(}?)/';
+ while (preg_match($pattern_var,$v,$regs)) {
+ $pieces = explode(" ",$pkgbuild["$regs[2]"],2);
+ $pattern = '/\$'.$regs[1].$regs[2].$regs[3].'/';
+ $replacement = $pieces[0];
+ $v=preg_replace($pattern, $replacement, $v);
+ }
$new_pkgbuild[$k] = $v;
}
}