Quantcast
Channel: Diary of a UAG Newbie
Viewing all articles
Browse latest Browse all 15

Secureremote to change one line. No, go wild with regex and change huge chunks!

$
0
0
I had a problem recently where I had to publish a web site where the "branding" was non existent, and looked horrific.  I wanted to bring it in line, and wanted to do it by replacing a chuck of HTML (the login form) with my own.

I did this using the WhlSecureRemote.xml file but came across a problem that the text was not actually consistent and was liable to change, and more annoyingly was over multiple lines.  The search tags in SecureRemote by default only check a single line as you cannot include linebreaks and whitespace in them.

The answer was to change my search tag to use regex: usually you start a search with <SEARCH encoding=""> (or encoding="base64" if you so desire) but there is another option in search for mode, so you can use <search encoding="" mode="regex">

Now you can match as much text as you want.  So I decided where I wanted to start the replace from (I used a parameter in the FORM tag in the HTML as a consistent place to anchor the start) and the end point (the end of the text in the form usefully always was "password.")

This looked something like:

<SEARCH encoding="" mode="regex">NAME="FormAuth">(\n|.)*password\.</SEARCH>

The key part of this is the (\n|.)* which says any number of characters and line breaks - .* only is any number of characters and does not include line breaks

The replace also started NAME="FormAuth"> but then had the html for our custom design for our login username and password, with the nice submit button and the CSS styles we use. The replace does not support regex (think about it, it can't predict what to write!) and I prefer to use base64 for the replace as you can include line breaks in base64, which makes your resulting HTML much tidier.

Job done - 10 days dev and testing replaced with 10 minutes of UAG coding.

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images