aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Taylan Ulrich B <taylanbayirli@gmail.com>2011-08-25 22:56:18 +0200
committerGravatar Brendan Taylor <whateley@gmail.com>2011-11-23 18:37:09 -0700
commit688d3f6b5c2e2911e1af8c002507921dfc368596 (patch)
treeef942da0ab2f874dc51ba1639bafc379f6612b43
parente2f3fe51149c8924b83899db87425ea1a462dc4b (diff)
various formfiller fixes
-rw-r--r--examples/data/scripts/formfiller.js9
-rwxr-xr-xexamples/data/scripts/formfiller.sh20
2 files changed, 22 insertions, 7 deletions
diff --git a/examples/data/scripts/formfiller.js b/examples/data/scripts/formfiller.js
index 1b10db4..06db648 100644
--- a/examples/data/scripts/formfiller.js
+++ b/examples/data/scripts/formfiller.js
@@ -29,6 +29,9 @@ uzbl.formfiller = {
for( var k = 0; k < inputs.length; ++k ) {
var input = inputs[k];
+ if ( ! input.name ) {
+ continue
+ }
if ( uzbl.formfiller.inputTypeIsText(input.type) ) {
rv += '%' + escape(input.name) + '(' + input.type + '):' + input.value + '\n';
} else if ( input.type == 'checkbox' || input.type == 'radio' ) {
@@ -39,8 +42,10 @@ uzbl.formfiller = {
var textareas = allFrames[j].document.getElementsByTagName("textarea");
for( var k = 0; k < textareas.length; ++k ) {
var textarea = textareas[k];
- rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/\n%/g,"\n\\%") + '\n%\n';
- rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/\n\\/g,"\n\\\\").replace(/\n%/g,"\n\\%") + '%\n';
+ if ( ! textarea.name ) {
+ continue
+ }
+ rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/(^|\n)\\/g,"$1\\\\").replace(/(^|\n)%/g,"$1\\%") + '\n%\n';
}
}
catch (err) { }
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 394bfbd..52d6ec6 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -63,6 +63,9 @@ ParseFields ()
awk '/^%/ {
sub ( /%/, "" )
+ gsub ( /\\/, "\\\\\\\\" )
+ gsub ( /@/, "\\@" )
+ gsub ( /"/, "\\\"" )
split( $0, parts, /\(|\)|\{|\}/ )
@@ -73,15 +76,24 @@ ParseFields ()
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",%s);\n",
parts[1], parts[2], parts[3], field )
- else if ( parts[2] ~ /^textarea$/ ) {
+ else if ( parts[2] == "textarea" ) {
field = ""
while (getline) {
if ( /^%/ ) break
sub ( /^\\/, "" )
+ # JavaScript escape
+ gsub ( /\\/, "\\\\\\\\" )
gsub ( /"/, "\\\"" )
- gsub ( /\\/, "\\\\" )
- field = field $0 "\\\\n"
+ # To support the possibility of the last line of the textarea
+ # not being terminated by a newline, we add the newline here.
+ # The "if (field)" is so that this does not happen in the first
+ # iteration.
+ if (field) field = field "\\n"
+ field = field $0
}
+ # Uzbl escape
+ gsub ( /\\/, "\\\\\\\\", field )
+ gsub ( /@/, "\\@", field )
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
parts[1], parts[2], field )
}
@@ -120,7 +132,6 @@ Load ()
ParseProfile $option < "$file" \
| ParseFields \
- | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}
@@ -136,7 +147,6 @@ Once ()
test -e "$tmpfile" &&
ParseFields < "$tmpfile" \
- | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}