Note that there are some explanatory texts on larger screens.

plurals
  1. PONoSuchMethoException on calling DefaultValidator.getValidFileName()
    primarykey
    data
    text
    <p>I am trying to use getValidFileName (String, String, list, boolean) method of DefaultValidator class from ESAPI provided jar (esapi-2.0_rc11) to validate file name. But on run time getting No such method exception.</p> <p>This is my code:</p> <pre><code>public static String getValidFileName(String input,String[] strFileExtns, Boolean isNullable) throws Exception { List &lt;String&gt; fileExtnsList = new ArrayList &lt;String&gt;(); if (strFileExtns != null &amp;&amp; strFileExtns.length &gt; 0) for(int i=0; i&lt;strFileExtns.length; i++) fileExtnsList.add(strFileExtns[i]); return new DefaultValidator().getValidFileName("FileNameValidation", input, fileExtnsList, isNullable); } </code></pre> <p>I am getting <code>java.lang.NoSuchMethodError:org/owasp/esapi/reference/DefaultValidator.getValidFileName(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)Ljava/lang/String;</code></p> <p>Code present in the jar:</p> <pre><code>public String getValidFileName(String context, String input, List&lt;String&gt; allowedExtensions, boolean allowNull) throws ValidationException, IntrusionException { if ((allowedExtensions == null) || (allowedExtensions.isEmpty())) { throw new ValidationException("Internal Error", "getValidFileName called with an empty or null list of allowed Extensions, therefore no files can be uploaded"); } String canonical = ""; try { if (isEmpty(input)) { if (allowNull) return null; throw new ValidationException(context + ": Input file name required", "Input required: context=" + context + ", input=" + input, context); } canonical = new File(input).getCanonicalFile().getName(); getValidInput(context, input, "FileName", 255, true); File f = new File(canonical); String c = f.getCanonicalPath(); String cpath = c.substring(c.lastIndexOf(File.separator) + 1); if (!(input.equals(cpath))) throw new ValidationException(context + ": Invalid file name", "Invalid directory name does not match the canonical path: context=" + context + ", input=" + input + ", canonical=" + canonical, context); } catch (IOException e) { throw new ValidationException(context + ": Invalid file name", "Invalid file name does not exist: context=" + context + ", canonical=" + canonical, e, context); } Iterator i = allowedExtensions.iterator(); while (i.hasNext()) { String ext = (String)i.next(); if (input.toLowerCase().endsWith(ext.toLowerCase())) return canonical; } throw new ValidationException(context + ": Invalid file name does not have valid extension ( " + allowedExtensions + ")", "Invalid file name does not have valid extension ( " + allowedExtensions + "): context=" + context + ", input=" + input, context); } </code></pre> <p>Someone please help me on this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload