What do you think about append "addslashes" util function ?

Issue #49 new
Stéphane Klein created an issue

What do you think about append "addslashes" util function (something named "webhelpers.util.addslashes") ?

Code like :


def addslashes(s):
d = {'"':'\"', "'":"\'", "\0":"\\0", "\":"\\"}
return ''.join(d.get(c, c) for c in s)

Use case :



<script type="text/javascript">

If you think it's a good idea, I can you send a patch with code and documentation.


Comments (4)

  1. Stéphane Klein reporter

    If I have :

    one_template_variable = "I don't know"

    and I execute :

    <script type="text/javascript">

    The result is :

    <script type="text/javascript">
    print('I don't know') // <= here there are an error

    It's more explicit ?

  2. Mike Orr

    I think this needs a more general solution, some kind of 'qoute' function that's told what the surrounding quotes are.

    It could also make the surrounding quotes itself, but that would only work if the helper expression is the entire quoted string, not interpolated within it.

  3. Log in to comment