@@ -326,6 +326,10 @@ public Regex DisallowCssPropertyValue
326
326
/// Occurs before a CSS class is removed.
327
327
/// </summary>
328
328
public event EventHandler < RemovingCssClassEventArgs > RemovingCssClass ;
329
+ /// <summary>
330
+ /// Occurs when a URL is being sanitized.
331
+ /// </summary>
332
+ public event EventHandler < FilterUrlEventArgs > FilterUrl ;
329
333
330
334
/// <summary>
331
335
/// Raises the <see cref="E:PostProcessDom" /> event.
@@ -404,6 +408,15 @@ protected virtual void OnRemovingCssClass(RemovingCssClassEventArgs e)
404
408
RemovingCssClass ? . Invoke ( this , e ) ;
405
409
}
406
410
411
+ /// <summary>
412
+ /// Raises the <see cref="E:RemovingUrl" /> event.
413
+ /// </summary>
414
+ /// <param name="e">The <see cref="FilterUrlEventArgs"/> instance containing the event data.</param>
415
+ protected virtual void OnFilteringUrl ( FilterUrlEventArgs e )
416
+ {
417
+ FilterUrl ? . Invoke ( this , e ) ;
418
+ }
419
+
407
420
/// <summary>
408
421
/// Return all nested subnodes of a node.
409
422
/// </summary>
@@ -829,13 +842,11 @@ protected Iri GetSafeIri(string url)
829
842
/// <param name="url">The URL.</param>
830
843
/// <param name="baseUrl">The base URL relative URLs are resolved against (empty or null for no resolution).</param>
831
844
/// <returns>The sanitized URL or null if no safe URL can be created.</returns>
832
- protected string SanitizeUrl ( string url , string baseUrl )
845
+ protected virtual string SanitizeUrl ( string url , string baseUrl )
833
846
{
834
847
var iri = GetSafeIri ( url ) ;
835
848
836
- if ( iri == null ) return null ;
837
-
838
- if ( ! iri . IsAbsolute && ! string . IsNullOrEmpty ( baseUrl ) )
849
+ if ( iri != null && ! iri . IsAbsolute && ! string . IsNullOrEmpty ( baseUrl ) )
839
850
{
840
851
// resolve relative uri
841
852
if ( Uri . TryCreate ( baseUrl , UriKind . Absolute , out Uri baseUri ) )
@@ -846,13 +857,16 @@ protected string SanitizeUrl(string url, string baseUrl)
846
857
}
847
858
catch ( UriFormatException )
848
859
{
849
- return null ;
860
+ iri = null ;
850
861
}
851
862
}
852
- else return null ;
863
+ else iri = null ;
853
864
}
854
865
855
- return iri . Value ;
866
+ var e = new FilterUrlEventArgs { OriginalUrl = url , SanitizedUrl = iri ? . Value } ;
867
+ OnFilteringUrl ( e ) ;
868
+
869
+ return e . SanitizedUrl ;
856
870
}
857
871
858
872
/// <summary>
0 commit comments