Skip to content

Move validate email address to page rather than in global roller.js - #243

Open
gregh3269 wants to merge 3 commits into
apache:roller-6.1.xfrom
gregh3269:roller-6.1.x-fix-email-validation-location
Open

gregh3269 wants to merge 3 commits into
apache:roller-6.1.xfrom
gregh3269:roller-6.1.x-fix-email-validation-location

Conversation

@gregh3269

Copy link
Copy Markdown
Contributor

Move validate email address to page rather than global roller.js. Stops template js errors and unnecessary checking.
".validate-email" class check seems only to be in one place.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Might want to add something to CHANGES.md about it

minlength: 3,
maxlength: 255,
email: true,
regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex was here before, but since it's moving: [A-Z]{2,4} rejects valid addresses with longer TLDs, such as user@example.museum, user@studio.photography or user@company.online, so those users can't create a weblog. Its maxlength of 255 also doesn't match the field's maxlength of 50. jQuery Validate's email: true already validates the format, so dropping the regex rule (or allowing TLDs of 2-63 characters) would fix it.

@gregh3269 gregh3269 Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a test I updated the regex from roller.js validateEmail
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
It works but now gets rejected up stream.

image

So I guess it never worked. For simplicity just drop the client validation, and fix up steam.

But its a struts issue
`

<field name="bean.emailAddress">
    <field-validator type="email">
        <message key="CreateWeblog.error.emailAddressBad">unspecified key</message>
    </field-validator>
</field>
`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing that. Good find that the server-side validator is the one rejecting long TLDs. I looked at the Struts 7.3.0 jar Roller ships: EmailValidator sets its pattern to end in ([a-z]{2,6}), so anything longer than six letters fails there. Dropping the client regex makes sense to me, as long as the server check stays. EmailValidator extends RegexFieldValidator, so a <param name="regex"> on the field-validator should let Roller use a looser pattern without waiting on Struts. I haven't tried that. Fine as a follow-up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more data point for this: roller.js already has a validateEmail() helper (around line 211) that Register.jsp, Profile.jsp and UserEdit.jsp use, and it accepts long TLDs. So today someone can register as jane@studio.photography and then fail this check when creating a weblog. If the regex rule goes, email: true with minlength covers the same ground and keeps the two forms consistent.

@mraible mraible left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Greg. Moving this into CreateWeblog.jsp fixes the errors on weblog pages that load roller.js, and it's the only page that uses these classes, so this looks right to me. A few small things inline.

This targets roller-6.1.x, but master still has the same block in roller.js (around lines 244-258), so it'll need a forward-port to master too.

Comment on lines +92 to +93
jQuery("form.validate-form").validate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these two lines have a tab and trailing whitespace, while the rest of the script uses 4-space indentation.

Suggested change
jQuery("form.validate-form").validate();
jQuery("form.validate-form").validate();

regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
});
});
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the file no longer ends with a newline.

regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
});
});
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, not for this PR: since roller.js also loads on public weblog pages, a guard around any page-specific setup that stays in here (for example, only running it when window.jQuery && jQuery.validator exist and form.validate-form is on the page) would stop this kind of error from coming back the next time a block is added.

@gregh3269

Copy link
Copy Markdown
Contributor Author

Hope its ok now. btw if you don't like my changes, I don't mind "changes to my changes" to make it work, as it stops more to and frow time wasting on such a minor mod.

Really just a heads up.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants