Giter Club home page Giter Club logo

Comments (5)

davisagli avatar davisagli commented on August 24, 2024

I'm guessing you're on an operating system where a new line actually is represented as two characters (linefeed + carriage return)

from products.ploneformgen.

adeste avatar adeste commented on August 24, 2024

I'm on ubuntu but i've the same problem on windows. Probably i've bad exposed my problem. If i have a textarea with a limit of 100 characters the js counter count every newline as one, but the form validator count it by two.

from products.ploneformgen.

mjfinney avatar mjfinney commented on August 24, 2024

I have also received complaints about this from users.
I've tested this with Plone running on OSX and CentOS. I've also tested this from Chrome on OSX and IE9 on Windows. I am always able to reproduce the issue. The javascript character count in the browser always counts newlines as one character but REQUEST.form['my-field'] always contains \r\n.

My solution was to change len(value) to len(value.replace('\r\n', '\n')) in the validation script. I will submit a pull request with this change.

from products.ploneformgen.

uschwarz avatar uschwarz commented on August 24, 2024

It's more seriously broken: it also counts non-ascii characters as multiple in the validator -- I guess it's the usual 7-bit-string issue: something like รค will have two bytes in UTF8, and the js correctly counts it as one character, whereas the validator sees it as two bytes.

from products.ploneformgen.

mjfinney avatar mjfinney commented on August 24, 2024

Yes I recently ran across the issue with non-ascii characters as well and have not found time to fix it. I'm not sure if I can reliably convert the string from the form to unicode. The below is an example of the problem and how converting to unicode strings fixes the problem. The pull request #70 is still needed to fix the newlines issue though.

emdash = '\xe2\x80\x94'
degree = '\xc2\xb0'
emdash
'\xe2\x80\x94'
print emdash
โ€”
len(emdash)
3
degree
'\xc2\xb0'
print degree
ยฐ
len(degree)
2

If you convert the string to unicode it is 1 character:

len(unicode(emdash, "UTF-8"))
1
len(unicode(degree, "UTF-8"))
1

from products.ploneformgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.