-
Notifications
You must be signed in to change notification settings - Fork 336
Read regex mobile regex through html dataset #9413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,15 +187,21 @@ | |
| <jsp:include page="includes/footer.jsp"/> | ||
| <% } %> | ||
|
|
||
| <div id="regexData" data-regex="<%=Encode.forHtmlAttribute(mobileRegex)%>" style="display:none;"></div> | ||
|
|
||
| <script type="text/javascript"> | ||
| $(document).ready(function() { | ||
| $('#update').click(function() { | ||
| var mobileNumber = document.getElementById("MOBILE_NUMBER").value; | ||
| var regexPattern = document.getElementById('regexData').dataset.regex; | ||
| // decode HTML-encoded backslashes for use in RegExp constructor | ||
| regexPattern = regexPattern.replace(/\\\\/g, "\\"); | ||
| var regexObj = new RegExp(regexPattern); | ||
| if (mobileNumber == "") { | ||
|
Comment on lines
+196
to
200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden regex construction and validation; avoid runtime breaks and over-unescaping
- var regexPattern = document.getElementById('regexData').dataset.regex;
- // decode HTML-encoded backslashes for use in RegExp constructor
- regexPattern = regexPattern.replace(/\\\\/g, "\\");
- var regexObj = new RegExp(regexPattern);
+ var regexObj = null;
+ var regexHolder = document.getElementById('regexData');
+ var regexPattern = regexHolder ? regexHolder.dataset.regex : "";
+ // Build regex only when policy is enabled and a non-empty pattern exists.
+ if (<%=validateMobileNumberFormat%> && regexPattern) {
+ try {
+ // Unescape only if we actually see double backslashes.
+ var pattern = regexPattern.indexOf("\\\\") >= 0
+ ? regexPattern.replace(/\\\\/g, "\\")
+ : regexPattern;
+ regexObj = new RegExp(pattern);
+ } catch (e) {
+ console.error("Invalid mobile regex pattern supplied:", e);
+ regexObj = null; // Fail open on client; server should still validate.
+ }
+ }
@@
- } else if (<%=validateMobileNumberFormat%> && !(regexObj.test(mobileNumber))) {
+ } else if (<%=validateMobileNumberFormat%> && regexObj && !(regexObj.test(mobileNumber.trim()))) {Additional minor tweak (outside the selected lines): consider Also applies to: 204-205 🤖 Prompt for AI Agents |
||
| document.getElementById('alertDiv').innerHTML | ||
| = '<div id="error-msg" class="ui negative message"><%=AuthenticationEndpointUtil.i18n(resourceBundle, "please.enter.mobile.number")%></div>' | ||
| +'<div class="ui divider hidden"></div>'; | ||
| } else if (<%=validateMobileNumberFormat%> && !(mobileNumber.match("<%=Encode.forJavaScript(mobileRegex)%>"))) { | ||
| } else if (<%=validateMobileNumberFormat%> && !(regexObj.test(mobileNumber))) { | ||
| document.getElementById('alertDiv').innerHTML | ||
| = '<div id="error-msg" class="ui negative message"><%=Encode.forHtml(mobileRegexPolicyValidationErrorMessage)%></div>' | ||
| +'<div class="ui divider hidden"></div>'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Avoid hardcoded text; use i18n key for the section heading
This file consistently uses
t(...)for labels. Hardcoding "Logout URL" breaks i18n/l10n. Prefer the existing translations (e.g., alogoutURLs.headingkey) or add a new singular key if needed.Run to confirm an existing heading key (adjust paths as needed):
🏁 Script executed:
Length of output: 44
Length of output: 1119
🏁 Script executed:
Length of output: 168
🏁 Script executed:
Length of output: 1063
🏁 Script executed:
Length of output: 27
Length of output: 2887
🏁 Script executed:
Length of output: 329
🏁 Script executed:
Length of output: 2772
🏁 Script executed:
Length of output: 1443
Length of output: 156
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 110
Use i18n translation key for "Logout URL" heading
Line 3912 is the only h4 heading in this file that is hardcoded; all others consistently use
t(...)for translations following the patternapplications:forms.inboundOIDC.sections.*. This breaks i18n/l10n consistency.📝 Committable suggestion
🤖 Prompt for AI Agents