1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 08:17:58 +01:00

add vimperator.util.escapeHTML

This commit is contained in:
Doug Kearns
2007-10-06 01:58:38 +00:00
parent b936238b5e
commit 2d1152cef9
8 changed files with 53 additions and 20 deletions

View File

@@ -262,11 +262,11 @@ function Bookmarks() //{{{
"<table><tr align=\"left\" class=\"hl-Title\"><th>title</th><th>keyword</th><th>URL</th><th align=\"right\">tags</th></tr>";
for (var i = 0; i < items.length; i++)
{
var title = items[i][1].replace(/</, "&lt;").replace(/>/, "&gt;");
var title = vimperator.util.escapeHTML(items[i][1]);
if (title.length > 50)
title = title.substr(0, 47) + "...";
var keyword = "".substr(0,12); // maximum 12 chars
var url = items[i][0].replace(/</, "&lt;").replace(/>/, "&gt;");
var url = vimperator.util.escapeHTML(items[i][0]);
var tags = "tag1, tag2";
list += "<tr><td>" + title + "</td><td style=\"color: blue\" align=\"center\">" + keyword +
"</td><td style=\"color: green; width: 100%\">" + url +
@@ -493,10 +493,10 @@ function History() //{{{
"<table><tr align=\"left\" class=\"hl-Title\"><th>title</th><th>URL</th></tr>";
for (var i = 0; i < items.length; i++)
{
var title = items[i][1].replace(/</, "&lt;").replace(/>/, "&gt;");
var title = vimperator.util.escapeHTML(items[i][1]);
if (title.length > 50)
title = title.substr(0, 47) + "...";
var url = items[i][0].replace(/</, "&lt;").replace(/>/, "&gt;");
var url = vimperator.util.escapeHTML(items[i][0]);
list += "<tr><td>" + title + "</td><td style=\"color: green;\">" + url + "</td></tr>";
}
list += "</table>";
@@ -753,7 +753,7 @@ function Marks() //{{{
+ "<td> " + marks[i][0] + "</td>"
+ "<td align=\"right\">" + Math.round(marks[i][1].position.y * 100) + "%</td>"
+ "<td align=\"right\">" + Math.round(marks[i][1].position.x * 100) + "%</td>"
+ "<td style=\"color: green;\">" + marks[i][1].location.replace(/</, "&lt;").replace(/>/, "&gt;") + "</td>"
+ "<td style=\"color: green;\">" + vimperator.util.escapeHTML(marks[i][1].location) + "</td>"
+ "</tr>";
}
list += "</table>";
@@ -846,7 +846,7 @@ function QuickMarks() //{{{
for (var i = 0; i < marks.length; i++)
{
list += "<tr><td> " + marks[i][0] +
"</td><td style=\"color: green;\">" + marks[i][1].replace(/</, "&lt;").replace(/>/, "&gt;") + "</td></tr>";
"</td><td style=\"color: green;\">" + vimperator.util.escapeHTML(marks[i][1]) + "</td></tr>";
}
list += "</table>";

View File

@@ -244,8 +244,8 @@ function Buffer() //{{{
[number, title] = items[i][0].split(/:\s+/, 2);
url = items[i][1];
url = url.replace(/>/, "&gt;").replace(/</, "&lt;");
title = title.replace(/>/, "&gt;").replace(/</, "&lt;");
url = vimperator.util.escapeHTML(url);
title = vimperator.util.escapeHTML(title);
list += "<tr><td align=\"right\"> " + number + "</td><td>" + indicator +
"</td><td style=\"width: 250px; max-width: 500px; overflow: hidden;\">" + title +

View File

@@ -503,7 +503,7 @@ function Commands() //{{{
if (typeof arg === "object")
arg = vimperator.objectToString(arg, color);
else if (typeof arg === "function")
arg = arg.toString().replace(/</g, "&lt;").replace(/>/, "&gt;");
arg = vimperator.util.escapeHTML(arg.toString());
else if (typeof arg === "number" || typeof arg === "boolean")
arg = "" + arg;
else if (typeof arg === "undefined")

View File

@@ -59,9 +59,7 @@ vimperator.help = function(section, easter) //{{{
// keep <br/>
//usage = usage.replace(/<([^b][^r].*>)/g, "&lt;$1");
//usage = usage.replace(/[^b][^r][^\/]>/g, "&gt;");
usage = usage.replace(/&/g, "&amp;");
usage = usage.replace(/</g, "&lt;");
usage = usage.replace(/>/g, "&gt;");
usage = vimperator.util.escapeHTML(usage);
usage = usage.replace(/\\n/g, "<br/>");
// color [count], [!], {arg} and [arg] in the usage, not nice and error prone but the regexp work (for now)
usage = usage.replace(/({[^}]+})/g, "<span class=\"argument\">$1</span>"); // required args
@@ -98,11 +96,7 @@ vimperator.help = function(section, easter) //{{{
for (var j=0; j < names.length; j++)
{
var cmd_name = names[j];
cmd_name = cmd_name.replace(/</g, "&lt;");
cmd_name = cmd_name.replace(/>/g, "&gt;");
// cmd_name = cmd_name.replace(/"/g, "&quot;");
// cmd_name = cmd_name.replace(/'/g, "&apos;");
// cmd_name = cmd_name.replace(/&/g, "&amp;");
cmd_name = vimperator.util.escapeHTML(cmd_name);
ret += '<code class="tag">' + beg + cmd_name + end + '</code><br/>';
}
ret += '</td></tr>';

View File

@@ -287,9 +287,9 @@ function Mappings() //{{{
for (var j = 0; j < maps[i].names.length; j++)
{
list += "<tr>";
list += "<td> " + maps[i].names[j].replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</td>"
list += "<td> " + vimperator.util.escapeHTML(maps[i].names[j]) + "</td>"
if (maps[i].rhs)
list += "<td> " + maps[i].rhs.replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</td>"
list += "<td> " + vimperator.util.escapeHTML(maps[i].rhs) + "</td>"
list += "</tr>";
}
}

38
content/util.js Normal file
View File

@@ -0,0 +1,38 @@
/***** BEGIN LICENSE BLOCK ***** {{{
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
(c) 2006-2007: Martin Stubenschrott <stubenschrott@gmx.net>
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
vimperator.util = {
escapeHTML: function(str)
{
var e = window.content.document.createElement("div");
e.appendChild(window.content.document.createTextNode(str));
return e.innerHTML;
}
}
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -406,7 +406,7 @@ const vimperator = (function() //{{{
{
var str = value.toString();
if (typeof str == "string") // can be "undefined"
value = str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
value = vimperator.util.escapeHTML(str);
}
}

View File

@@ -53,6 +53,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<script type="application/x-javascript;version=1.7" src="options.js"/>
<script type="application/x-javascript;version=1.7" src="tabs.js"/>
<script type="application/x-javascript;version=1.7" src="ui.js"/>
<script type="application/x-javascript;version=1.7" src="util.js"/>
<window id="main-window">