diff options
author | Brett Porter <brett@apache.org> | 2011-10-03 01:56:43 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2011-10-03 01:56:43 +0000 |
commit | 242cfa1f9a54d92f025cf688b95761895603acf2 (patch) | |
tree | 401d1a5b0ccd813469d41c4f03c97b5257f3b0aa /archiva-modules | |
parent | ea1e15a65d797983954ee88f87944bb3ed11303d (diff) | |
download | archiva-242cfa1f9a54d92f025cf688b95761895603acf2.tar.gz archiva-242cfa1f9a54d92f025cf688b95761895603acf2.zip |
add a patched version of Struts form template that corrects WW-3688 for URL
validation, and re-enable appearance tests
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178285 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
2 files changed, 133 insertions, 5 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/AppearanceTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/AppearanceTest.java index 1d2f7ad5f..4d4facf33 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/AppearanceTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/AppearanceTest.java @@ -78,27 +78,25 @@ public class AppearanceTest assertTextPresent( "You must enter a URL for your logo." ); } - @Test(enabled = false) + @Test public void testAddAppearanceValidValues() { goToAppearancePage(); clickLinkWithText( "Edit" ); - // FIXME: not allowed this URL for the logo?! addEditAppearance( "The Apache Software Foundation", "http://www.apache.org/", "http://www.apache.org/images/asf_logo_wide.gifs", true ); assertTextPresent( "The Apache Software Foundation" ); } - @Test( dependsOnMethods = { "testAddAppearanceValidValues" }, enabled = false) + @Test( dependsOnMethods = { "testAddAppearanceValidValues" } ) public void testEditAppearance() { goToAppearancePage(); clickLinkWithText( "Edit" ); - // FIXME: not allowed this URL for the logo?! addEditAppearance( "Apache Software Foundation", "http://www.apache.org/", "http://www.apache.org/images/asf_logo_wide.gifs", true ); assertTextPresent( "Apache Software Foundation" ); } -}
\ No newline at end of file +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/template/xhtml/form-close-validate.ftl b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/template/xhtml/form-close-validate.ftl new file mode 100644 index 000000000..49d3a2314 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/template/xhtml/form-close-validate.ftl @@ -0,0 +1,130 @@ +<#-- +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +--> +<#-- +START SNIPPET: supported-validators +Only the following validators are supported: +* required validator +* requiredstring validator +* stringlength validator +* regex validator +* email validator +* url validator +* int validator +* double validator +END SNIPPET: supported-validators +--> +<#if ((parameters.validate?default(false) == true) && (parameters.performValidation?default(false) == true))> +<script type="text/javascript"> + function validateForm_${parameters.id?replace('[^a-zA-Z0-9_]', '_', 'r')}() { + form = document.getElementById("${parameters.id}"); + clearErrorMessages(form); + clearErrorLabels(form); + + var errors = false; + var continueValidation = true; + <#list parameters.tagNames as tagName> + <#list tag.getValidators("${tagName}") as validator> + // field name: ${validator.fieldName} + // validator name: ${validator.validatorType} + if (form.elements['${validator.fieldName}']) { + field = form.elements['${validator.fieldName}']; + var error = "${validator.getMessage(action)?js_string}"; + <#if validator.validatorType = "required"> + if (field.value == "") { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + <#elseif validator.validatorType = "requiredstring"> + if (continueValidation && field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + <#elseif validator.validatorType = "stringlength"> + if (continueValidation && field.value != null) { + var value = field.value; + <#if validator.trim> + //trim field value + while (value.substring(0,1) == ' ') + value = value.substring(1, value.length); + while (value.substring(value.length-1, value.length) == ' ') + value = value.substring(0, value.length-1); + </#if> + if ((${validator.minLength?c} > -1 && value.length < ${validator.minLength?c}) || + (${validator.maxLength?c} > -1 && value.length > ${validator.maxLength?c})) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + } + <#elseif validator.validatorType = "regex"> + if (continueValidation && field.value != null && !field.value.match("${validator.expression?js_string}")) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + <#elseif validator.validatorType = "email"> + if (continueValidation && field.value != null && field.value.length > 0 && field.value.match(/\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi)==null) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + <#elseif validator.validatorType = "url"> + if (continueValidation && field.value != null && field.value.length > 0 && field.value.match(/^(ftp|http|https):\/\/((%[A-F0-9]{2}|[A-Z0-9-._~!$&'()*+,;=:])+@)?((%[A-F0-9]{2}|[A-Z0-9-._~!$&'()*+,;=])+)(:[0-9]+)?((\/(%[A-F0-9]{2}|[A-Z0-9-._~!$&'()*+,;=:@])*)*)(\?(%[A-F0-9]{2}|[A-Z0-9-._~!$&'()*+,;=:@/?])*)?(#(%[A-F0-9]{2}|[A-Z0-9-._~!$&'()*+,;=:@/?])*)?$/gi)==null) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + <#elseif validator.validatorType = "int"> + if (continueValidation && field.value != null) { + if (<#if validator.min??>parseInt(field.value) < + ${validator.min?c}<#else>false</#if> || + <#if validator.max??>parseInt(field.value) > + ${validator.max?c}<#else>false</#if>) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + } + <#elseif validator.validatorType = "double"> + if (continueValidation && field.value != null) { + var value = parseFloat(field.value); + if (<#if validator.minInclusive??>value < ${validator.minInclusive}<#else>false</#if> || + <#if validator.maxInclusive??>value > ${validator.maxInclusive}<#else>false</#if> || + <#if validator.minExclusive??>value <= ${validator.minExclusive}<#else>false</#if> || + <#if validator.maxExclusive??>value >= ${validator.maxExclusive}<#else>false</#if>) { + addError(field, error); + errors = true; + <#if validator.shortCircuit>continueValidation = false;</#if> + } + } + </#if> + } + </#list> + </#list> + + return !errors; + } +</script> +</#if> |