Gossamer Forum
Home : General : Perl Programming :

perl/sql escaping characters

(Page 2 of 2)
> >
Quote Reply
Re: perl/sql escaping characters In reply to
What is it with us coders? We always have to do it in the shortest way possible ;)



-----------
Crowe (crowe@lit.org)
Quote Reply
Re: perl/sql escaping characters In reply to
Laziness....hehe....don't want to type too much :)

Ooops I got the + and ? the wrong way round in the last example.....

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: perl/sql escaping characters In reply to
hmm that last example won't work the way it is, period.

Do you want me to fix it up or are you happy using .?.?.?

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: perl/sql escaping characters In reply to
OK it would have irritated me forever so I made it EVEN shorter...lol...and it works.....

s/(\[)(\/?.+?)(\])/<$2>/g;

I'll leave you in peace now.



Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: perl/sql escaping characters In reply to
Well ?.?.?. works fine, but using your last example

$hash{answer} =~ s/(\[)(\/?..?)(\])/<$2>/g;

Works even better, just no + at all ;) It appears to be working fine. I'm still doing some testing but I haven't had one miss yet. Been using
  • and more. Haven't done anyting with longer than 2 though. I'll try that next. As long as stuff like DIV works, it should be fine.

    Will this catch arguements to html? ex <table width="50%"> ?

    Going to try it now and see!

    -----------
    Crowe (crowe@lit.org)
  • Quote Reply
    Re: perl/sql escaping characters In reply to
    Nope it should ignore anything not in square brackets.

    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    It did not like my table example ;)

    I'm sure with just a bit more tweaking though I can nail it down.


    -----------
    Crowe (crowe@lit.org)
    Quote Reply
    Re: perl/sql escaping characters In reply to
    How do you mean?

    What happened?

    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    Well, using:

    $hash{answer} =~ s/(\[)(\/?..?)(\])/<$2>/g;

    And trying [TABLE WIDTH="50%"][TR][TD]TEST[/TD][/TR][/TABLE]
    produced bizzare results, natrually. :)



    -----------
    Crowe (crowe@lit.org)
    Quote Reply
    Re: perl/sql escaping characters In reply to
    This should work for your table tag and for any others like b, i, li, div etc...


    s/(\[)(\/?.+?)(\])/<$2>/g;

    (I tested it and it worked as expected).


    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    Indeed it did. Sweet. ;)

    So where did you do all your regex studying? I have a much better understanding today than I did yesterday, but I've got a good bit to learn. A couple of months ago I wouldn't have even tried this! regex looks so... so... Alien to "REGULAR EXPRESSION" .. hah. regular expression sounds like it would me.

    "please replace THIS with THAT"

    But no, its more like cryptic RUNES or magic symbols of some sort. I guess they are kinda like magic though :)

    It's one thing when you can see the word exists in the regex, like my examples with bold, but when it's all characters and you don't know what each means, it just looks insane, like gibberish..heh.

    Again, thanks for the help!

    -----------
    Crowe (crowe@lit.org)
    Quote Reply
    Re: perl/sql escaping characters In reply to
    Hey believe me, a month or so ago I felt the same way, but by trial and error and a lot of practice I am sort of getting to grips with it. Here are some nice resources.....

    http://virtual.park.uga.edu/humcomp/perl/regex2a.html
    http://www.perl.com/pub/doc/manual/html/pod/perlre.html

    All the slashes (amongst other things) make it look complicated but most of them are just escaping something else like in my fist example near the top of the thread (\\$1) - just a backslash being escaped.

    Anyway those links should be quite helpful.


    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    They indeed do look awesome.

    Just to let everyone know what I've been up to with this script, it is a perl/mysql faq manager. You can ADD/EDIT/DELETE/ARCHIVE posts and manage catagories. This first version will be added to our system here that already has a user auth scheme.

    I will release this code when its done and I'll post the link here. In the release version it will include a user auth scheme. We have something like 300 faq's ( this is an isp ) and everyone has been maintaining them by hand.

    Thanks for the links, they do look great! I'll be reading through them quite a bit!



    -----------
    Crowe (crowe@lit.org)
    Quote Reply
    Re: perl/sql escaping characters In reply to
    Oh cool, I could do with something like that for my hosting site.

    I have just started using links2 as a faq database. I am only using search.cgi, links.db and linksid.txt along with db.pl and db_utils.pl but it works great...

    http://www.wiredon.net/faq/search.cgi?q=path

    I may give your script a whirl when it is ready if I may or write my own if I get the time..lol. Is your script going to be free or..?

    If you use my regex I want full credit and a link back to my site and royalties.

    LOL...just kidding.

    I'm just waiting now for Alex, GClemmons, Mark etc..to tell me how bad or insecure my regex is Smile

    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    your regex has useless stuff in it..

    could be..
    s!\[(/?\w+)\]!<$1>!g;

    could be even smaller.. but uhh.. i'm not in a thinking mood..

    y/\[\]/<>/g;

    that works too

    Jerry Su
    http://www.jsu07.com
    Quote Reply
    Re: perl/sql escaping characters In reply to
    Hey as I said, I'm only learning Smile

    Paul
    Installations:http://wiredon.net/gt/
    Support: http://wiredon.net/forum/

    Quote Reply
    Re: perl/sql escaping characters In reply to
    Yeah, I plan on it being free! I should have a beta ready in about a week or so. I just have to rewrite some of the subs with the new stuff I've learned, write a couple of docs and create the menu! Most of the hard stuff is done, not it's just the grunt work as I like to call it ;)

    -----------
    Crowe (crowe@lit.org)
    Quote Reply
    Re: perl/sql escaping characters In reply to
    keep in mind what you are using it for and what the consequences could be.

    if you just start replacing braces someone could signifigantly hose your page.
    [iframe ...]

    or

    [script]
    document.location.href='someOtherUrl';

    just something to keep in mind.
    if you want to keep a strict limit on what people can use you can simply create an array of useable character combinations and regex foreach through it.

    -g



    s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
    Quote Reply
    Re: perl/sql escaping characters In reply to
    Absolutely. This is something I've been considering. What I'm thinking of doing is in the private version, allowing all html. These are html guys and programmers after all and if they want to include something, so be it. This paticular app is just to make it easier for them to manage their faq documents. They are all employees who will be usising it.

    In the public version however, I think I will limit it to stuff like B|I|LI|EM etc etc. Jus some of the basic formatting. I'll probably just impliment UBB compatible code for the public release. Why ask users to learn something new?

    --Chris


    -----------
    Crowe (crowe@lit.org)
    > >