|
<mvt:miva output="on" compresswhitespace="off" /> |
|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Encoding Test</title> |
|
<style> |
|
body { |
|
font-family: sans-serif; |
|
font-size: 120%; |
|
} |
|
th { |
|
text-align: right; |
|
} |
|
td { |
|
font-family: monospace; |
|
padding: 5px; |
|
} |
|
th, td { |
|
border-bottom: 1px solid #f5f5f5; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
|
|
<h1>MivaScript encodeentities() & encodeattribute()<br> vs. JavaScript encodeURI() & encodeURIComponent()</h1> |
|
|
|
<mvt:assign name="l.settings:test:reserved_characters" value="';/?:@&=+$,#'" /> |
|
<mvt:assign name="l.settings:test:unreserved_marks" value="'-.!~*\'()'" /> |
|
<mvt:assign name="l.settings:test:alpha_numeric_and_space" value="'ABC abc 123'" /> |
|
<mvt:assign name="l.settings:test:url" value="'https://jsmith:[email protected]:443/path/to some/file.html?q=s&q2=a+b&q3=some thing#hash=value'" /> |
|
|
|
<script> |
|
const test = <mvt:eval expr="miva_json_encode( l.settings:test, l.null )" /> |
|
</script> |
|
|
|
<h2>Reserved Characters</h2> |
|
|
|
<table> |
|
<tr> |
|
<th>Original</th> |
|
<td>&mvt:test:reserved_characters;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvte</th> |
|
<td>&mvte:test:reserved_characters;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvta</th> |
|
<td>&mvta:test:reserved_characters;</td> |
|
</tr> |
|
<tr> |
|
<th>encodeURI()</th> |
|
<td><script>document.write(encodeURI(test.reserved_characters))</script></td> |
|
</tr> |
|
<tr> |
|
<th>encodeURIComponent()</th> |
|
<td><script>document.write(encodeURIComponent(test.reserved_characters))</script></td> |
|
</tr> |
|
</table> |
|
|
|
<h2>Unreserved Marks</h2> |
|
|
|
<table> |
|
<tr> |
|
<th>Original</th> |
|
<td>&mvt:test:unreserved_marks;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvte</th> |
|
<td>&mvte:test:unreserved_marks;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvta</th> |
|
<td>&mvta:test:unreserved_marks;</td> |
|
</tr> |
|
<tr> |
|
<th>encodeURI()</th> |
|
<td><script>document.write(encodeURI(test.unreserved_marks))</script></td> |
|
</tr> |
|
<tr> |
|
<th>encodeURIComponent()</th> |
|
<td><script>document.write(encodeURIComponent(test.unreserved_marks))</script></td> |
|
</tr> |
|
</table> |
|
|
|
<h2>Alpha Numeric and Space</h2> |
|
|
|
<table> |
|
<tr> |
|
<th>Original</th> |
|
<td>&mvt:test:alpha_numeric_and_space;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvte</th> |
|
<td>&mvte:test:alpha_numeric_and_space;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvta</th> |
|
<td>&mvta:test:alpha_numeric_and_space;</td> |
|
</tr> |
|
<tr> |
|
<th>encodeURI()</th> |
|
<td><script>document.write(encodeURI(test.alpha_numeric_and_space))</script></td> |
|
</tr> |
|
<tr> |
|
<th>encodeURIComponent()</th> |
|
<td><script>document.write(encodeURIComponent(test.alpha_numeric_and_space))</script></td> |
|
</tr> |
|
</table> |
|
|
|
<h2>URL</h2> |
|
|
|
<table> |
|
<tr> |
|
<th>Original</th> |
|
<td>&mvt:test:url;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvte</th> |
|
<td>&mvte:test:url;</td> |
|
</tr> |
|
<tr> |
|
<th>&mvta</th> |
|
<td>&mvta:test:url;</td> |
|
</tr> |
|
<tr> |
|
<th>encodeURI()</th> |
|
<td><script>document.write(encodeURI(test.url))</script></td> |
|
</tr> |
|
<tr> |
|
<th>encodeURIComponent()</th> |
|
<td><script>document.write(encodeURIComponent(test.url))</script></td> |
|
</tr> |
|
</table> |
|
|
|
<hr> |
|
|
|
<h2>asciichar()</h2> |
|
|
|
<mvt:assign name="l.settings:num" value="0" /> |
|
<table> |
|
<tr> |
|
<th>#</th> |
|
<th>Original</th> |
|
<th>&mvte</th> |
|
<th>&mvta</th> |
|
<th>encodeURI()</th> |
|
<th>encodeURIComponent()</th> |
|
</tr> |
|
<mvt:while expr="l.settings:num LT 256"> |
|
<mvt:assign name="l.settings:char" value="asciichar(l.settings:num)" /> |
|
<tr> |
|
<th>&mvt:num;</th> |
|
<td>&mvt:char;</td> |
|
<td>&mvte:char;</td> |
|
<td>&mvta:char;</td> |
|
<td><script>document.write(encodeURI('&mvtj:char;'))</script></td> |
|
<td><script>document.write(encodeURIComponent('&mvtj:char;'))</script></td> |
|
</tr> |
|
<mvt:assign name="l.settings:num" value="l.settings:num + 1" /> |
|
</mvt:while> |
|
</table> |
|
|
|
</body> |
|
</html> |