From 952c8856098dcfd9673d344fc71be85b303c8fb1 Mon Sep 17 00:00:00 2001
From: Andy Staudacher
Date: Sat, 29 Aug 2009 22:31:23 -0700
Subject: Adding html::clean(), ::purify(), etc.
---
modules/gallery/tests/Html_Helper_Test.php | 55 ++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 modules/gallery/tests/Html_Helper_Test.php
(limited to 'modules/gallery/tests/Html_Helper_Test.php')
diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php
new file mode 100644
index 00000000..4d934ad5
--- /dev/null
+++ b/modules/gallery/tests/Html_Helper_Test.php
@@ -0,0 +1,55 @@
+world
");
+ $this->assert_equal("hello <p >world</p>",
+ $safe_string);
+ $this->assert_true($safe_string instanceof SafeString);
+ }
+
+ public function purify_test() {
+ $safe_string = html::purify("hello world<\\/p>",
+ $string);
+ }
+
+ public function clean_attribute_test() {
+ $safe_string = SafeString::of_safe_html("hello's
Date: Sat, 29 Aug 2009 22:54:20 -0700
Subject: Update all code to use helper method html::clean(), html::purify(),
... instead of SafeString directly.
---
modules/comment/controllers/comments.php | 8 ++++----
modules/comment/helpers/comment_rss.php | 8 ++++----
modules/comment/views/admin_block_recent_comments.html.php | 6 +++---
modules/comment/views/admin_comments.html.php | 10 +++++-----
modules/comment/views/comment.html.php | 6 +++---
modules/comment/views/comment.mrss.php | 12 ++++++------
modules/comment/views/comments.html.php | 6 +++---
modules/digibug/controllers/digibug.php | 2 +-
modules/exif/views/exif_dialog.html.php | 4 ++--
modules/g2_import/helpers/g2_import.php | 2 +-
modules/gallery/controllers/admin_advanced_settings.php | 2 +-
modules/gallery/controllers/quick.php | 10 +++++-----
modules/gallery/helpers/MY_html.php | 4 ++--
modules/gallery/helpers/gallery_rss.php | 4 ++--
modules/gallery/helpers/gallery_task.php | 4 ++--
modules/gallery/tests/Html_Helper_Test.php | 4 ++--
modules/gallery/tests/Xss_Security_Test.php | 4 ++--
modules/gallery/views/admin_advanced_settings.html.php | 6 +++---
modules/gallery/views/admin_block_log_entries.html.php | 2 +-
modules/gallery/views/admin_block_photo_stream.html.php | 4 ++--
modules/gallery/views/admin_languages.html.php | 4 ++--
modules/gallery/views/admin_maintenance.html.php | 4 ++--
modules/gallery/views/admin_maintenance_show_log.html.php | 2 +-
modules/gallery/views/move_tree.html.php | 8 ++++----
modules/gallery/views/permissions_browse.html.php | 4 ++--
modules/gallery/views/permissions_form.html.php | 2 +-
modules/gallery/views/simple_uploader.html.php | 14 +++++++-------
modules/info/views/info_block.html.php | 10 +++++-----
modules/notification/views/comment_published.html.php | 12 ++++++------
modules/notification/views/item_added.html.php | 8 ++++----
modules/notification/views/item_deleted.html.php | 6 +++---
modules/notification/views/item_updated.html.php | 12 ++++++------
modules/organize/views/organize_dialog.html.php | 2 +-
modules/organize/views/organize_tree.html.php | 6 +++---
modules/rss/views/feed.mrss.php | 14 +++++++-------
modules/rss/views/rss_block.html.php | 2 +-
modules/search/views/search.html.php | 6 +++---
modules/server_add/views/admin_server_add.html.php | 2 +-
modules/server_add/views/server_add_tree.html.php | 4 ++--
modules/server_add/views/server_add_tree_dialog.html.php | 6 +++---
modules/tag/controllers/admin_tags.php | 2 +-
modules/tag/views/admin_tags.html.php | 6 +++---
modules/tag/views/tag_cloud.html.php | 2 +-
modules/user/controllers/logout.php | 2 +-
modules/user/views/admin_users.html.php | 8 ++++----
modules/user/views/admin_users_group.html.php | 4 ++--
modules/user/views/login.html.php | 2 +-
themes/default/views/album.html.php | 6 +++---
themes/default/views/dynamic.html.php | 4 ++--
themes/default/views/header.html.php | 4 ++--
themes/default/views/movie.html.php | 4 ++--
themes/default/views/photo.html.php | 6 +++---
52 files changed, 143 insertions(+), 143 deletions(-)
(limited to 'modules/gallery/tests/Html_Helper_Test.php')
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 87633f4c..82b12893 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -39,9 +39,9 @@ class Comments_Controller extends REST_Controller {
foreach ($comments as $comment) {
$data[] = array(
"id" => $comment->id,
- "author_name" => SafeString::of($comment->author_name()),
+ "author_name" => html::clean($comment->author_name()),
"created" => $comment->created,
- "text" => nl2br(SafeString::purify($comment->text)));
+ "text" => nl2br(html::purify($comment->text)));
}
print json_encode($data);
break;
@@ -126,9 +126,9 @@ class Comments_Controller extends REST_Controller {
array("result" => "success",
"data" => array(
"id" => $comment->id,
- "author_name" => SafeString::of($comment->author_name()),
+ "author_name" => html::clean($comment->author_name()),
"created" => $comment->created,
- "text" => nl2br(SafeString::purify($comment->text)))));
+ "text" => nl2br(html::purify($comment->text)))));
} else {
$view = new Theme_View("comment.html", "fragment");
$view->comment = $comment;
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php
index 4151dcd0..b539887b 100644
--- a/modules/comment/helpers/comment_rss.php
+++ b/modules/comment/helpers/comment_rss.php
@@ -23,7 +23,7 @@ class comment_rss_Core {
$feeds["comment/newest"] = t("All new comments");
if ($item) {
$feeds["comment/item/$item->id"] =
- t("Comments on %title", array("title" => SafeString::purify($item->title)));
+ t("Comments on %title", array("title" => html::purify($item->title)));
}
return $feeds;
}
@@ -49,13 +49,13 @@ class comment_rss_Core {
$item = $comment->item();
$feed->children[] = new ArrayObject(
array("pub_date" => date("D, d M Y H:i:s T", $comment->created),
- "text" => nl2br(SafeString::purify($comment->text)),
+ "text" => nl2br(html::purify($comment->text)),
"thumb_url" => $item->thumb_url(),
"thumb_height" => $item->thumb_height,
"thumb_width" => $item->thumb_width,
"item_uri" => url::abs_site("{$item->type}s/$item->id"),
- "title" => SafeString::purify($item->title),
- "author" => SafeString::of($comment->author_name())),
+ "title" => html::purify($item->title),
+ "author" => html::clean($comment->author_name())),
ArrayObject::ARRAY_AS_PROPS);
}
diff --git a/modules/comment/views/admin_block_recent_comments.html.php b/modules/comment/views/admin_block_recent_comments.html.php
index 2c7a5cf1..dc3975e0 100644
--- a/modules/comment/views/admin_block_recent_comments.html.php
+++ b/modules/comment/views/admin_block_recent_comments.html.php
@@ -4,13 +4,13 @@
">
"
class="gAvatar"
- alt="= SafeString::of($comment->author_name()) ?>"
+ alt="= html::clean($comment->author_name()) ?>"
width="32"
height="32" />
= gallery::date_time($comment->created) ?>
= t('%author_name said %comment_text ',
- array("author_name" => SafeString::of($comment->author_name()),
- "comment_text" => text::limit_words(nl2br(SafeString::purify($comment->text)), 50))); ?>
+ array("author_name" => html::clean($comment->author_name()),
+ "comment_text" => text::limit_words(nl2br(html::purify($comment->text)), 50))); ?>
endforeach ?>
diff --git a/modules/comment/views/admin_comments.html.php b/modules/comment/views/admin_comments.html.php
index 8b0b4c29..801ce2b3 100644
--- a/modules/comment/views/admin_comments.html.php
+++ b/modules/comment/views/admin_comments.html.php
@@ -108,12 +108,12 @@
"
class="gAvatar"
- alt="= SafeString::of($comment->author_name()) ?>"
+ alt="= html::clean($comment->author_name()) ?>"
width="40"
height="40" />
- = SafeString::of($comment->author_name()) ?>
+ = html::clean($comment->author_name()) ?>
= gallery::date($comment->created) ?>
- = nl2br(SafeString::purify($comment->text)) ?>
+ = nl2br(html::purify($comment->text)) ?>
- = SafeString::of($details[$i]["value"]) ?>
+ = html::clean($details[$i]["value"]) ?>
if (!empty($details[++$i])): ?>
= $details[$i]["caption"] ?>
- = SafeString::of($details[$i]["value"]) ?>
+ = html::clean($details[$i]["value"]) ?>
else: ?>
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index a01ca1db..7e5c6f75 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -590,7 +590,7 @@ class g2_import_Core {
self::map($g2_comment->getId(), $comment->id);
return t("Imported comment '%comment' for item with id: %id",
array("id" => $comment->item_id,
- "comment" => text::limit_words(nl2br(SafeString::purify($comment->text)), 50)));
+ "comment" => text::limit_words(nl2br(html::purify($comment->text)), 50)));
}
/**
diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php
index d727b654..43c77340 100644
--- a/modules/gallery/controllers/admin_advanced_settings.php
+++ b/modules/gallery/controllers/admin_advanced_settings.php
@@ -46,7 +46,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller {
module::set_var($module_name, $var_name, Input::instance()->post("value"));
message::success(
t("Saved value for %var (%module_name)",
- array("var" => SafeString::of($var_name), "module_name" => $module_name)));
+ array("var" => html::clean($var_name), "module_name" => $module_name)));
print json_encode(array("result" => "success"));
}
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 8fddb563..20731f9c 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -75,7 +75,7 @@ class Quick_Controller extends Controller {
access::required("view", $item->parent());
access::required("edit", $item->parent());
- $msg = t("Made %title this album's cover", array("title" => SafeString::purify($item->title)));
+ $msg = t("Made %title this album's cover", array("title" => html::purify($item->title)));
item::make_album_cover($item);
message::success($msg);
@@ -91,10 +91,10 @@ class Quick_Controller extends Controller {
if ($item->is_album()) {
print t(
"Delete the album %title ? All photos and movies in the album will also be deleted.",
- array("title" => SafeString::purify($item->title)));
+ array("title" => html::purify($item->title)));
} else {
print t("Are you sure you want to delete %title ?",
- array("title" => SafeString::purify($item->title)));
+ array("title" => html::purify($item->title)));
}
$form = item::get_delete_form($item);
@@ -108,9 +108,9 @@ class Quick_Controller extends Controller {
access::required("edit", $item);
if ($item->is_album()) {
- $msg = t("Deleted album %title ", array("title" => SafeString::purify($item->title)));
+ $msg = t("Deleted album %title ", array("title" => html::purify($item->title)));
} else {
- $msg = t("Deleted photo %title ", array("title" => SafeString::purify($item->title)));
+ $msg = t("Deleted photo %title ", array("title" => html::purify($item->title)));
}
$parent = $item->parent();
diff --git a/modules/gallery/helpers/MY_html.php b/modules/gallery/helpers/MY_html.php
index eb388811..75114898 100644
--- a/modules/gallery/helpers/MY_html.php
+++ b/modules/gallery/helpers/MY_html.php
@@ -65,11 +65,11 @@ class html extends html_Core {
*
* Example:
*
-
= t("Organize %name", array("name" => SafeString::purify($album->title))) ?>
+
= t("Organize %name", array("name" => html::purify($album->title))) ?>
diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php
index 387d5977..5b676889 100644
--- a/modules/organize/views/organize_tree.html.php
+++ b/modules/organize/views/organize_tree.html.php
@@ -5,7 +5,7 @@
- = SafeString::of($parent->title) ?>
+ = html::clean($parent->title) ?>
endforeach ?>
@@ -17,7 +17,7 @@
"
ref="= $peer->id ?>">
- = SafeString::of($peer->title) ?>
+ = html::clean($peer->title) ?>
if ($peer->id == $album->id): ?>
@@ -29,7 +29,7 @@
- = SafeString::of($child->title) ?>
+ = html::clean($child->title) ?>
endforeach ?>
diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php
index 7298b7f4..731703c7 100644
--- a/modules/rss/views/feed.mrss.php
+++ b/modules/rss/views/feed.mrss.php
@@ -6,9 +6,9 @@
xmlns:fh="http://purl.org/syndication/history/1.0">
gallery3
- = SafeString::of($feed->title) ?>
+ = html::clean($feed->title) ?>
= $feed->uri ?>
- = SafeString::of($feed->description) ?>
+ = html::clean($feed->description) ?>
en-us
@@ -22,25 +22,25 @@
= $pub_date ?>
foreach ($feed->children as $child): ?>
-
-
= SafeString::of($child->title) ?>
+ = html::clean($child->title) ?>
= url::abs_site("{$child->type}s/{$child->id}") ?>
= url::abs_site("{$child->type}s/{$child->id}") ?>
= date("D, d M Y H:i:s T", $child->created); ?>
= SafeString::of($child->description) ?>
+ = html::clean($child->description) ?>
if ($child->type == "photo" || $child->type == "album"): ?>
else: ?>
type}s/{$child->id}") ?>">
endif ?>
- = SafeString::of($child->description) ?>
+ = html::clean($child->description) ?>
]]>
diff --git a/modules/rss/views/rss_block.html.php b/modules/rss/views/rss_block.html.php
index cd8db89d..737731b6 100644
--- a/modules/rss/views/rss_block.html.php
+++ b/modules/rss/views/rss_block.html.php
@@ -5,7 +5,7 @@
- = SafeString::purify($title) ?>
+ = html::purify($title) ?>
diff --git a/modules/search/views/search.html.php b/modules/search/views/search.html.php
index e5c7b4a6..7963948d 100644
--- a/modules/search/views/search.html.php
+++ b/modules/search/views/search.html.php
@@ -8,7 +8,7 @@
diff --git a/modules/server_add/views/server_add_tree.html.php b/modules/server_add/views/server_add_tree.html.php
index 2f65a590..dbae42c5 100644
--- a/modules/server_add/views/server_add_tree.html.php
+++ b/modules/server_add/views/server_add_tree.html.php
@@ -10,7 +10,7 @@
- = SafeString::of(basename($dir)) ?>
+ = html::clean(basename($dir)) ?>
endforeach ?>
@@ -24,7 +24,7 @@
endif ?>
file="= strtr($file, array('"' => '\\"')) ?>"
>
- = SafeString::of(basename($file)) ?>
+ = html::clean(basename($file)) ?>
endforeach ?>
diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php
index 912e69b6..8eb6e4df 100644
--- a/modules/server_add/views/server_add_tree_dialog.html.php
+++ b/modules/server_add/views/server_add_tree_dialog.html.php
@@ -5,17 +5,17 @@
-
= t("Add Photos to '%title'", array("title" => SafeString::purify($item->title))) ?>
+
= t("Add Photos to '%title'", array("title" => html::purify($item->title))) ?>
= t("Photos will be added to album:") ?>
foreach ($item->parents() as $parent): ?>
- = SafeString::purify($parent->title) ?>
+ = html::purify($parent->title) ?>
endforeach ?>
- = SafeString::purify($item->title) ?>
+ = html::purify($item->title) ?>
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php
index f1b4ca3a..8b8dde21 100644
--- a/modules/tag/controllers/admin_tags.php
+++ b/modules/tag/controllers/admin_tags.php
@@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller {
array("result" => "success",
"location" => url::site("admin/tags"),
"tag_id" => $tag->id,
- "new_tagname" => SafeString::of($tag->name)));
+ "new_tagname" => html::clean($tag->name)));
} else {
print json_encode(
array("result" => "error",
diff --git a/modules/tag/views/admin_tags.html.php b/modules/tag/views/admin_tags.html.php
index 30dd0728..3d805c5e 100644
--- a/modules/tag/views/admin_tags.html.php
+++ b/modules/tag/views/admin_tags.html.php
@@ -32,7 +32,7 @@
$current_letter = strtoupper(mb_substr($tag->name, 0, 1)) ?>
if ($i == 0): /* first letter */ ?>
-
= SafeString::of($current_letter) ?>
+
= html::clean($current_letter) ?>
elseif ($last_letter != $current_letter): /* new letter */ ?>
if ($column_tag_count > $tags_per_column): /* new column */ ?>
@@ -42,12 +42,12 @@
endif ?>
-
= SafeString::of($current_letter) ?>
+
= html::clean($current_letter) ?>
diff --git a/modules/user/controllers/logout.php b/modules/user/controllers/logout.php
index 4b141a1c..fc3ced56 100644
--- a/modules/user/controllers/logout.php
+++ b/modules/user/controllers/logout.php
@@ -24,7 +24,7 @@ class Logout_Controller extends Controller {
$user = user::active();
user::logout();
log::info("user", t("User %name logged out", array("name" => $user->name)),
- html::anchor("user/$user->id", SafeString::of($user->name)));
+ html::anchor("user/$user->id", html::clean($user->name)));
if ($continue_url = $this->input->get("continue")) {
$item = url::get_item_from_uri($continue_url);
if (access::can("view", $item)) {
diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php
index 36c4f4fd..9455f9d9 100644
--- a/modules/user/views/admin_users.html.php
+++ b/modules/user/views/admin_users.html.php
@@ -68,16 +68,16 @@
"
title="= t("Drag user onto group below to add as a new member") ?>"
- alt="= SafeString::of($user->name) ?>"
+ alt="= html::clean($user->name) ?>"
width="20"
height="20" />
- = SafeString::of($user->name) ?>
+ = html::clean($user->name) ?>
- = SafeString::of($user->full_name) ?>
+ = html::clean($user->full_name) ?>
- = SafeString::of($user->email) ?>
+ = html::clean($user->email) ?>
= ($user->last_login == 0) ? "" : gallery::date($user->last_login) ?>
diff --git a/modules/user/views/admin_users_group.html.php b/modules/user/views/admin_users_group.html.php
index f89a4392..8418ebc9 100644
--- a/modules/user/views/admin_users_group.html.php
+++ b/modules/user/views/admin_users_group.html.php
@@ -1,6 +1,6 @@
"
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index 8c690f5f..caabeee3 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -2,8 +2,8 @@
// @todo Set hover on AlbumGrid list items for guest users ?>
= $theme->album_top() ?>
-
= SafeString::purify($item->title) ?>
-
= nl2br(SafeString::purify($item->description)) ?>
+
= html::purify($item->title) ?>
+
= nl2br(html::purify($item->description)) ?>
= $theme->thumb_bottom($child) ?>
= $theme->context_menu($child, "#gItemId-{$child->id} .gThumbnail") ?>
-
+
diff --git a/themes/default/views/dynamic.html.php b/themes/default/views/dynamic.html.php
index 2d8e04a2..9ed9d69b 100644
--- a/themes/default/views/dynamic.html.php
+++ b/themes/default/views/dynamic.html.php
@@ -3,7 +3,7 @@
- = SafeString::of($title) ?>
+ = html::clean($title) ?>
*
*
* @return the string escaped for use in JavaScript.
*/
function for_js() {
- return self::_escape_for_js($this->_raw_string);
+ return json_encode((string) $this->_raw_string);
}
/**
@@ -152,14 +152,6 @@ class SafeString_Core {
return html::specialchars($dirty_html);
}
- // Escapes special chars (quotes, backslash, etc.) with a backslash sequence.
- private static function _escape_for_js($string) {
- // From Smarty plugins/modifier.escape.php
- // Might want to be stricter here.
- return strtr($string,
- array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n',''=>'<\/'));
- }
-
// Purifies the string, removing any potentially malicious or unsafe HTML / JavaScript.
private static function _purify_for_html($dirty_html) {
if (empty(self::$_purifier)) {
diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php
index a9903256..f5ce7fa4 100644
--- a/modules/gallery/tests/Html_Helper_Test.php
+++ b/modules/gallery/tests/Html_Helper_Test.php
@@ -40,9 +40,9 @@ class Html_Helper_Test extends Unit_Test_Case {
$safe_string_2);
}
- public function clean_js_test() {
- $string = html::clean_js("hello's world
");
- $this->assert_equal("hello\\'s world<\\/p>",
+ public function js_string_test() {
+ $string = html::js_string("hello's
world
");
+ $this->assert_equal('"hello\'s world<\\/p>"',
$string);
}
diff --git a/modules/gallery/tests/SafeString_Test.php b/modules/gallery/tests/SafeString_Test.php
index 0fc7f6f3..ede55240 100644
--- a/modules/gallery/tests/SafeString_Test.php
+++ b/modules/gallery/tests/SafeString_Test.php
@@ -49,7 +49,7 @@ class SafeString_Test extends Unit_Test_Case {
public function for_js_test() {
$safe_string = new SafeString('"Foo \'s bar"');
$js_string = $safe_string->for_js();
- $this->assert_equal('\\"Foo<\\/em>\\\'s bar\\"',
+ $this->assert_equal('"\\"Foo<\\/em>\'s bar\\""',
$js_string);
}
@@ -96,21 +96,21 @@ class SafeString_Test extends Unit_Test_Case {
public function of_fluid_api_test() {
$escaped_string = SafeString::of("Foo's bar")->for_js();
- $this->assert_equal("Foo\\'s bar", $escaped_string);
+ $this->assert_equal('"Foo\'s bar"', $escaped_string);
}
public function safestring_of_safestring_preserves_safe_status_test() {
$safe_string = SafeString::of_safe_html("hello's world
");
$safe_string_2 = new SafeString($safe_string);
$this->assert_equal("hello's world
", $safe_string_2);
- $this->assert_equal("hello\\'s world<\\/p>", $safe_string_2->for_js());
+ $this->assert_equal('"hello\'s
world<\\/p>"', $safe_string_2->for_js());
}
public function safestring_of_safestring_preserves_html_safe_status_test() {
$safe_string = SafeString::of_safe_html("hello's
world
");
$safe_string_2 = new SafeString($safe_string);
$this->assert_equal("hello's world
", $safe_string_2);
- $this->assert_equal("hello\\'s world<\\/p>", $safe_string_2->for_js());
+ $this->assert_equal('"hello\'s
world<\\/p>"', $safe_string_2->for_js());
}
public function safestring_of_safestring_safe_status_override_test() {
diff --git a/modules/gallery/tests/Xss_Security_Test.php b/modules/gallery/tests/Xss_Security_Test.php
index b385580d..3a22afc1 100644
--- a/modules/gallery/tests/Xss_Security_Test.php
+++ b/modules/gallery/tests/Xss_Security_Test.php
@@ -188,7 +188,7 @@ class Xss_Security_Test extends Unit_Test_Case {
if (self::_token_matches(array(T_DOUBLE_COLON, "::"), $tokens, $token_number + 1) &&
self::_token_matches(array(T_STRING), $tokens, $token_number + 2) &&
in_array($tokens[$token_number + 2][1],
- array("clean", "purify", "clean_js", "clean_attribute")) &&
+ array("clean", "purify", "js_string", "clean_attribute")) &&
self::_token_matches("(", $tokens, $token_number + 3)) {
// Not checking for mark_safe(). We want such calls to be marked dirty (thus reviewed).
@@ -198,7 +198,7 @@ class Xss_Security_Test extends Unit_Test_Case {
$token_number += 3;
$token = $tokens[$token_number];
- if ("clean_js" == $method) {
+ if ("js_string" == $method) {
$frame->is_safe_js(true);
} else {
$frame->is_safe_html(true);
--
cgit v1.2.3
From df38a890a64dd33eafe3aed51ce8fde732cf8b8b Mon Sep 17 00:00:00 2001
From: Andy Staudacher
Date: Sun, 30 Aug 2009 18:07:13 -0700
Subject: Tabs to spaces cleanup
---
modules/gallery/controllers/admin_languages.php | 32 +-
modules/gallery/controllers/l10n_client.php | 8 +-
modules/gallery/helpers/gallery.php | 6 +-
modules/gallery/libraries/SafeString.php | 4 +-
modules/gallery/tests/Html_Helper_Test.php | 10 +-
modules/gallery/tests/SafeString_Test.php | 14 +-
modules/gallery/tests/Xss_Security_Test.php | 380 ++++++++++++------------
modules/server_add/helpers/server_add_event.php | 2 +-
8 files changed, 228 insertions(+), 228 deletions(-)
(limited to 'modules/gallery/tests/Html_Helper_Test.php')
diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php
index b1bc4cff..d85c47f9 100644
--- a/modules/gallery/controllers/admin_languages.php
+++ b/modules/gallery/controllers/admin_languages.php
@@ -21,10 +21,10 @@ class Admin_Languages_Controller extends Admin_Controller {
public function index($share_translations_form=null) {
$v = new Admin_View("admin.html");
$v->content = new View("admin_languages.html");
- $v->content->available_locales = locales::available();
+ $v->content->available_locales = locales::available();
$v->content->installed_locales = locales::installed();
$v->content->default_locale = module::get_var("gallery", "default_locale");
-
+
if (empty($share_translations_form)) {
$share_translations_form = $this->_share_translations_form();
}
@@ -35,21 +35,21 @@ class Admin_Languages_Controller extends Admin_Controller {
public function save() {
access::verify_csrf();
-
- locales::update_installed($this->input->post("installed_locales"));
-
- $installed_locales = array_keys(locales::installed());
+
+ locales::update_installed($this->input->post("installed_locales"));
+
+ $installed_locales = array_keys(locales::installed());
$new_default_locale = $this->input->post("default_locale");
- if (!in_array($new_default_locale, $installed_locales)) {
- if (!empty($installed_locales)) {
- $new_default_locale = $installed_locales[0];
- } else {
- $new_default_locale = "en_US";
- }
- }
- module::set_var("gallery", "default_locale", $new_default_locale);
-
- print json_encode(array("result" => "success"));
+ if (!in_array($new_default_locale, $installed_locales)) {
+ if (!empty($installed_locales)) {
+ $new_default_locale = $installed_locales[0];
+ } else {
+ $new_default_locale = "en_US";
+ }
+ }
+ module::set_var("gallery", "default_locale", $new_default_locale);
+
+ print json_encode(array("result" => "success"));
}
public function share() {
diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php
index 0775791e..16d39024 100644
--- a/modules/gallery/controllers/l10n_client.php
+++ b/modules/gallery/controllers/l10n_client.php
@@ -90,13 +90,13 @@ class L10n_Client_Controller extends Controller {
}
$session = Session::instance();
- $l10n_mode = $session->get("l10n_mode", false);
+ $l10n_mode = $session->get("l10n_mode", false);
$session->set("l10n_mode", !$l10n_mode);
$redirect_url = "admin/languages";
- if (!$l10n_mode) {
- $redirect_url .= "#l10n-client";
- }
+ if (!$l10n_mode) {
+ $redirect_url .= "#l10n-client";
+ }
url::redirect($redirect_url);
}
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 122227fc..035ed1da 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -92,7 +92,7 @@ class gallery_Core {
$can_add = $item && access::can("add", $item);
if ($can_add) {
- $menu->append($add_menu = Menu::factory("submenu")
+ $menu->append($add_menu = Menu::factory("submenu")
->id("add_menu")
->label(t("Add")));
$add_menu->append(Menu::factory("dialog")
@@ -100,11 +100,11 @@ class gallery_Core {
->label(t("Add photos"))
->url(url::site("simple_uploader/app/$item->id")));
if ($item->is_album()) {
- $add_menu->append(Menu::factory("dialog")
+ $add_menu->append(Menu::factory("dialog")
->id("add_album_item")
->label(t("Add an album"))
->url(url::site("form/add/albums/$item->id?type=album")));
- }
+ }
}
$menu->append($options_menu = Menu::factory("submenu")
diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php
index 0767a665..cc542e01 100644
--- a/modules/gallery/libraries/SafeString.php
+++ b/modules/gallery/libraries/SafeString.php
@@ -120,8 +120,8 @@ class SafeString_Core {
function for_html_attr() {
$string = (string) $this->for_html();
return strtr($string,
- array("'"=>"'",
- '"'=>'"'));
+ array("'"=>"'",
+ '"'=>'"'));
}
/**
diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php
index f5ce7fa4..3623705e 100644
--- a/modules/gallery/tests/Html_Helper_Test.php
+++ b/modules/gallery/tests/Html_Helper_Test.php
@@ -21,14 +21,14 @@ class Html_Helper_Test extends Unit_Test_Case {
public function clean_test() {
$safe_string = html::clean("hello world
");
$this->assert_equal("hello <p >world</p>",
- $safe_string);
+ $safe_string);
$this->assert_true($safe_string instanceof SafeString);
}
public function purify_test() {
$safe_string = html::purify("hello world
");
$this->assert_equal("hello world
",
- $safe_string);
+ $safe_string);
$this->assert_true($safe_string instanceof SafeString);
}
@@ -37,19 +37,19 @@ class Html_Helper_Test extends Unit_Test_Case {
$this->assert_true($safe_string instanceof SafeString);
$safe_string_2 = html::clean($safe_string);
$this->assert_equal("hello world
",
- $safe_string_2);
+ $safe_string_2);
}
public function js_string_test() {
$string = html::js_string("hello's world
");
$this->assert_equal('"hello\'s world<\\/p>"',
- $string);
+ $string);
}
public function clean_attribute_test() {
$safe_string = SafeString::of_safe_html("hello's
world
");
$safe_string = html::clean_attribute($safe_string);
$this->assert_equal("hello's world
",
- $safe_string);
+ $safe_string);
}
}
\ No newline at end of file
diff --git a/modules/gallery/tests/SafeString_Test.php b/modules/gallery/tests/SafeString_Test.php
index ede55240..0895b7dd 100644
--- a/modules/gallery/tests/SafeString_Test.php
+++ b/modules/gallery/tests/SafeString_Test.php
@@ -21,19 +21,19 @@ class SafeString_Test extends Unit_Test_Case {
public function toString_escapes_for_html_test() {
$safe_string = new SafeString("hello world
");
$this->assert_equal("hello <p>world</p>",
- $safe_string);
+ $safe_string);
}
public function toString_for_safe_string_test() {
$safe_string = SafeString::of_safe_html("hello world
");
$this->assert_equal("hello world
",
- $safe_string);
+ $safe_string);
}
public function for_html_test() {
$safe_string = new SafeString("hello world
");
$this->assert_equal("hello <p>world</p>",
- $safe_string->for_html());
+ $safe_string->for_html());
}
public function safestring_of_safestring_test() {
@@ -50,27 +50,27 @@ class SafeString_Test extends Unit_Test_Case {
$safe_string = new SafeString('"Foo \'s bar"');
$js_string = $safe_string->for_js();
$this->assert_equal('"\\"Foo<\\/em>\'s bar\\""',
- $js_string);
+ $js_string);
}
public function for_html_attr_test() {
$safe_string = new SafeString('"Foo \'s bar"');
$attr_string = $safe_string->for_html_attr();
$this->assert_equal('"<em>Foo</em>'s bar"',
- $attr_string);
+ $attr_string);
}
public function for_html_attr_with_safe_html_test() {
$safe_string = SafeString::of_safe_html('"Foo \'s bar"');
$attr_string = $safe_string->for_html_attr();
$this->assert_equal('"Foo 's bar"',
- $attr_string);
+ $attr_string);
}
public function string_safestring_equality_test() {
$safe_string = new SafeString("hello world
");
$this->assert_equal("hello world
",
- $safe_string->unescaped());
+ $safe_string->unescaped());
$escaped_string = "hello <p>world</p>";
$this->assert_equal($escaped_string, $safe_string);
diff --git a/modules/gallery/tests/Xss_Security_Test.php b/modules/gallery/tests/Xss_Security_Test.php
index 3a22afc1..6c141c52 100644
--- a/modules/gallery/tests/Xss_Security_Test.php
+++ b/modules/gallery/tests/Xss_Security_Test.php
@@ -24,9 +24,9 @@ class Xss_Security_Test extends Unit_Test_Case {
// List of all tokens without whitespace, simplifying parsing.
$tokens = array();
foreach (token_get_all(file_get_contents($view)) as $token) {
- if (!is_array($token) || ($token[0] != T_WHITESPACE)) {
- $tokens[] = $token;
- }
+ if (!is_array($token) || ($token[0] != T_WHITESPACE)) {
+ $tokens[] = $token;
+ }
}
$frame = null;
@@ -34,199 +34,199 @@ class Xss_Security_Test extends Unit_Test_Case {
$in_script_block = false;
for ($token_number = 0; $token_number < count($tokens); $token_number++) {
- $token = $tokens[$token_number];
-
- // Are we in a block?
- if (is_array($token) && $token[0] == T_INLINE_HTML) {
- $inline_html = $token[1];
- // T_INLINE_HTML blocks can be split. Need to handle the case
- // where one token has "expr_append($inline_html);
- }
-
- // Note: This approach won't catch }i', $inline_html, $matches, PREG_OFFSET_CAPTURE)) {
- $last_match = array_pop($matches[0]);
- if (is_array($last_match)) {
- $closing_script_pos = $last_match[1];
- } else {
- $closing_script_pos = $last_match;
- }
- }
- if (preg_match('{ block?
+ if (is_array($token) && $token[0] == T_INLINE_HTML) {
+ $inline_html = $token[1];
+ // T_INLINE_HTML blocks can be split. Need to handle the case
+ // where one token has "expr_append($inline_html);
+ }
+
+ // Note: This approach won't catch }i', $inline_html, $matches, PREG_OFFSET_CAPTURE)) {
+ $last_match = array_pop($matches[0]);
+ if (is_array($last_match)) {
+ $closing_script_pos = $last_match[1];
+ } else {
+ $closing_script_pos = $last_match;
+ }
+ }
+ if (preg_match('{