HTML Batch String Parser

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SirJosh3917
Posts: 35
Joined: 02 May 2016 18:59

HTML Batch String Parser

#1 Post by SirJosh3917 » 29 Oct 2016 12:30

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>
 
Attachments
HTML string parser.zip
HTML parser for batch strings
(762 Bytes) Downloaded 89 times

penpen
Expert
Posts: 1723
Joined: 23 Jun 2013 06:15
Location: Germany

Re: HTML Batch String Parser

#2 Post by penpen » 29 Oct 2016 13:36

There is a bug in your code:
The percentage sign ('%') cannot be escaped using "^%", it has to be escaped using "%%".

penpen

SirJosh3917
Posts: 35
Joined: 02 May 2016 18:59

Re: HTML Batch String Parser

#3 Post by SirJosh3917 » 29 Oct 2016 13:52

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...

penpen
Expert
Posts: 1723
Joined: 23 Jun 2013 06:15
Location: Germany

Re: HTML Batch String Parser

#4 Post by penpen » 29 Oct 2016 15:30

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

Post Reply