ChickenFur
ChickenFur

Reputation: 2400

html textarea submission causing '=' chars to display at new lines only when deployed on GAE

When I submit the following text in my textarea box on the windows GAE launcher at http://localhost:8080 it displays fine.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a dolor eget diam
condimentum varius. Proin malesuada dictum ante, sed commodo purus vestibulum in. 
Sed nibh dui, volutpat eu porta eu, molestie ut lacus. Vivamus iaculis urna ut tellus 
blandit eu at nisl. Fusce eros libero, aliquam vitae hendrerit vitae, posuere ac diam. 
Vivamus sagittis, felis in imperdiet pellentesque, eros nibh porttitor nisi, id      
tristique leo libero a ligula. In in elit et velit auctor lacinia eleifend cursus mauris. Mauris 
pellentesque lorem et augue placerat ultrices. Nam sed quam nisl, eget elementum felis. 
Integer sapien ipsum, aliquet quis viverra quis, adipiscing eget sapien. Nam consequat 
lacinia enim, id viverra nisl molestie feugiat.

When my code is deployed on GAE after I hit the submit button it displays like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a dolor eg=
et diam condimentum varius. Proin malesuada dictum ante, sed commodo purus =
vestibulum in. Sed nibh dui, volutpat eu porta eu, molestie ut lacus. Vivam=
us iaculis urna ut tellus tempor blandit eu at nisl. Fusce eros libero, ali=
quam vitae hendrerit vitae, posuere ac diam. Vivamus sagittis, felis in imp=
erdiet pellentesque, eros nibh porttitor nisi, id tristique leo libero a li=
gula. In in elit et velit auctor lacinia eleifend cursus mauris. Mauris pel=
lentesque lorem et augue placerat ultrices. Nam sed quam nisl, eget element=
um felis. Integer sapien ipsum, aliquet quis viverra quis, adipiscing eget =
sapien. Nam consequat lacinia enim, id viverra nisl molestie feugiat.

Implementation Description below:

I am using the jinja2 engine. I have autescape = false:

jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = False)

I get the content from a textarea element. Here is how it is set in my template:

  <label>
    <div>Information</div>
    <textarea name="information">{{r.information}}</textarea>
  </label>

I retrieve the string using:

information = self.request.get('information')

I committ the string to the data store

r.information = information
r.put()

When displaying it again for editing I use the same template code:

  <label>
    <div>Information</div>
    <textarea name="information">{{r.information}}</textarea>
  </label>

Everything works great locally. But when I deploy it to the google app engine I am getting some strange results. Where do those = signs come from I wonder?

EDIT:
For clarification it is putting =CRLF at the end of every line.

*EDIT 2: * Here is the code from comment 21 of the bug:

def from_fieldstorage(cls, fs):
    """
    Create a dict from a cgi.FieldStorage instance
    """
    obj = cls()
    if fs.list:
        # fs.list can be None when there's nothing to parse
        for field in fs.list:
            if field.filename:
                obj.add(field.name, field)
            else:

                # first, set a common charset to utf-8.
                common_charset = 'utf-8'

                # second, check Content-Transfer-Encoding and decode
                # the value appropriately
                field_value = field.value
                transfer_encoding = field.headers.get(
                  'Content-Transfer-Encoding', None)

                if transfer_encoding == 'base64':
                    field_value = base64.b64decode(field_value)

                if transfer_encoding == 'quoted-printable':
                    field_value = quopri.decodestring(field_value)

                if field.type_options.has_key('charset') and \
                      field.type_options['charset'] != common_charset:
                    # decode with a charset specified in each
                    # multipart, and then encode it again with a
                    # charset specified in top level FieldStorage
                    field_value = field_value.decode(
                      field.type_options['charset']).encode(common_charset)

            # TODO: Should we take care of field.name here?
            obj.add(field.name, field_value)

    return obj

multidict.MultiDict.from_fieldstorage = classmethod(from_fieldstorage)

Upvotes: 1

Views: 215

Answers (1)

Greg
Greg

Reputation: 10360

You might be falling foul of this bug The workaround in comment 21 has worked for me in the past, and recent comments indicate it still does.

Upvotes: 1

Related Questions