Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Last active February 13, 2023 18:58
Show Gist options
  • Select an option

  • Save steveosoule/e57fffad92903cdeebd90975e1d428d5 to your computer and use it in GitHub Desktop.

Select an option

Save steveosoule/e57fffad92903cdeebd90975e1d428d5 to your computer and use it in GitHub Desktop.
Encoding Test

Miva & JavaScript Encoding Test

Encoding Value
Original https://jsmith:[email protected]:443/path/to some/file.html?q=s&q2=a+b&q3=some thing#hash=value
&mvte https://jsmith:[email protected]:443/path/to some/file.html?q=s&q2=a+b&q3=some thing#hash=value
encodeURI() https://jsmith:[email protected]:443/path/to%20some/file.html?q=s&q2=a+b&q3=some%20thing#hash=value
&mvta https%3A%2F%2Fjsmith%[email protected]%3A443%2Fpath%2Fto+some%2Ffile.html%3Fq%3Ds%26q2%3Da%2Bb%26q3%3Dsome+thing%23hash%3Dvalue
encodeURIComponent() https%3A%2F%2Fjsmith%3Afoo%40www.example.com%3A443%2Fpath%2Fto%20some%2Ffile.html%3Fq%3Ds%26q2%3Da%2Bb%26q3%3Dsome%20thing%23hash%3Dvalue

View https://ssoule.mivamerchantdev.com/store/mivascript-js-encoding.html for an example of the entire output.

<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>&amp;mvte</th>
<td>&mvte:test:reserved_characters;</td>
</tr>
<tr>
<th>&amp;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>&amp;mvte</th>
<td>&mvte:test:unreserved_marks;</td>
</tr>
<tr>
<th>&amp;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>&amp;mvte</th>
<td>&mvte:test:alpha_numeric_and_space;</td>
</tr>
<tr>
<th>&amp;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>&amp;mvte</th>
<td>&mvte:test:url;</td>
</tr>
<tr>
<th>&amp;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>&amp;mvte</th>
<th>&amp;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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment