From 688d3f6b5c2e2911e1af8c002507921dfc368596 Mon Sep 17 00:00:00 2001 From: Taylan Ulrich B Date: Thu, 25 Aug 2011 22:56:18 +0200 Subject: various formfiller fixes --- examples/data/scripts/formfiller.js | 9 +++++++-- examples/data/scripts/formfiller.sh | 20 +++++++++++++++----- 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" } -- cgit v1.2.3