[CentralOH] 2014-11-14 道場 Scribbles: Injection Attacks

Bryan Harris brywilharris at gmail.com
Mon Nov 17 18:17:21 CET 2014


I find it hard to believe there isn't some sort of "Sanitize Inputs"
library.  Pypi has a bunch of libraries which do some sort of sanitization.

https://pypi.python.org/pypi?%3Aaction=search&term=sanitize&submit=search
On Nov 17, 2014 10:52 AM, "Joe Shaw" <joe at joeshaw.org> wrote:

> Hi,
>
> I'd probably iterate over the string and increment a paren counter.  If it
> ever went < 0, it's unbalanced and bail out. At the end, if it's > 0, it's
> not properly closed.  This is basically a very lame lexer/parser state
> machine. Something like:
>
> for s in strings:
>     paren_level = 0
>     for i, c in enumerate(s):
>         if c == '(':
>             paren_level += 1
>         elif c == ')':
>             paren_level -= 1
>         if paren_level < 0:
>             print "{}: Unbalanced closing paren at pos {}: '{}'".format(s,
> i, c)
>             break
>     # obviously would be better to track the position of the last open
> paren
>     if paren_level > 0:
>        print "{}: Unclosed opening paren somewhere".format(s)
>
> Joe
>
> On Mon, Nov 17, 2014 at 10:39 AM, Eric Floehr <eric at intellovations.com>
> wrote:
>
>> for s in strings:
>>>     print(repr(s), s.count('(') == s.count(')'))
>>>
>>
>> But that will return true for ")this) isn't balanced( b)ut (says it( is"
>>
>>
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> https://mail.python.org/mailman/listinfo/centraloh
>>
>>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20141117/a608aec8/attachment.html>


More information about the CentralOH mailing list