Page 1 of 1

HTML Batch String Parser

Posted: 29 Oct 2016 12:30
by SirJosh3917
This HTML page allows you to type something in and it'll automatically parse it as a safe to echo string.

Code: Select all

 <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script>
            //Definer Functions
           
            String.prototype.replaceAll = function(search, replacement) {
                var target = this;
                return target.split(search).join(replacement);
            };
           
            //jQuery
           
            $(function(){
                $('#sname').on('input', function() {
                    var test = $(this).val();
                    var lines = $('#soutname').val();
                    lines = bStrParse(test);
                    $("#soutname").html(lines);
                });
            });
           
            function bStrParse(str) {
                var replace = "^~!@%$&*()\"><\\/";
                var ret = str;
                len = replace.length;
                for (var i = 0; i < len; i++)
                {
                    var check = replace[i];
                    ret = ret.replaceAll(check, "^" + check);
                }
                return ret;
            }
        </script>
        <style>
            #code, #vname, #download {
                width: 100%;
            }
            #shutdown_fieldset, #appinstall, #startup, #usb {
                width = 50%;
            }
        </style>
        <title> B V M </title>
    </head>
     <body>
        <input type="text" name="sname" id="sname" value="String to parse into a safe string"><br><br>
         <textarea name="soutname" class="soutname" id="soutname">String to parse into a safe string</textarea>
     </body>
 </html>
 

Re: HTML Batch String Parser

Posted: 29 Oct 2016 13:36
by penpen
There is a bug in your code:
The percentage sign ('%') cannot be escaped using "^%", it has to be escaped using "%%".

penpen

Re: HTML Batch String Parser

Posted: 29 Oct 2016 13:52
by SirJosh3917
penpen wrote:There is a bug in your code:
The percentage sign ('%') cannot be escaped using "^%", it has to be escaped using "%%".

penpen


Command prompt says

Code: Select all

C:\Users\__>set a=b

C:\Users\__>echo ^%a^%
%a%

C:\Users\__>echo %%a%%
%b%

:\Users\__>


But a batch file crashes with ^%a^%

Is there any way to tell you're running command prompt versus using a batch file?

I could just do some fancy tricks using LEFT TO RIGHT OVERRIDE
err... no that's visible in cmd...

Re: HTML Batch String Parser

Posted: 29 Oct 2016 15:30
by penpen
SirJosh3917 wrote:Is there any way to tell you're running command prompt versus using a batch file?
How do you mean this?
If i don't misunderstand anything your above is pure html code.
I'm pretty sure there is no (browser independent) way to check how this page has been opened.

You could add a second text area and use one for dos prompt and one for batch files.

If you need some text to check if you are running from command, then these lines could help (although seldomly used):

Code: Select all

set runFromCmdLine=false
goto :label
set runFromCmdLine=true
:label
If runFromCmdLine contains true, then you are running from a command line, else you are within a batch file.

Sidenote:
You could also escape the string using pure batch only.


penpen