5
5
using Umbraco . Cms . Core . Models . PublishedContent ;
6
6
using Umbraco . Cms . Core . PropertyEditors ;
7
7
using Umbraco . Cms . Core . Routing ;
8
+ using Umbraco . Extensions ;
8
9
9
10
namespace Umbraco . StorageProviders
10
11
{
@@ -38,7 +39,7 @@ public CdnMediaUrlProvider(IOptionsMonitor<CdnMediaUrlProviderOptions> options,
38
39
39
40
_cdnUrl = options . CurrentValue . Url ;
40
41
_removeMediaFromPath = options . CurrentValue . RemoveMediaFromPath ;
41
- _mediaPath = hostingEnvironment . ToAbsolute ( globalSettings . CurrentValue . UmbracoMediaPath ) . TrimEnd ( '/' ) ;
42
+ _mediaPath = hostingEnvironment . ToAbsolute ( globalSettings . CurrentValue . UmbracoMediaPath ) . EnsureEndsWith ( '/' ) ;
42
43
43
44
options . OnChange ( ( options , name ) =>
44
45
{
@@ -53,7 +54,7 @@ public CdnMediaUrlProvider(IOptionsMonitor<CdnMediaUrlProviderOptions> options,
53
54
{
54
55
if ( name == Options . DefaultName )
55
56
{
56
- _mediaPath = hostingEnvironment . ToAbsolute ( options . UmbracoMediaPath ) . TrimEnd ( '/' ) ;
57
+ _mediaPath = hostingEnvironment . ToAbsolute ( options . UmbracoMediaPath ) . EnsureEndsWith ( '/' ) ;
57
58
}
58
59
} ) ;
59
60
}
@@ -65,12 +66,18 @@ public CdnMediaUrlProvider(IOptionsMonitor<CdnMediaUrlProviderOptions> options,
65
66
if ( mediaUrl ? . IsUrl == true )
66
67
{
67
68
string url = mediaUrl . Text ;
69
+
70
+ int startIndex = 0 ;
68
71
if ( _removeMediaFromPath && url . StartsWith ( _mediaPath , StringComparison . OrdinalIgnoreCase ) )
69
72
{
70
- url = url [ _mediaPath . Length ..] ;
73
+ startIndex = _mediaPath . Length ;
74
+ }
75
+ else if ( url . StartsWith ( '/' ) )
76
+ {
77
+ startIndex = 1 ;
71
78
}
72
79
73
- return UrlInfo . Url ( _cdnUrl + url , culture ) ;
80
+ return UrlInfo . Url ( _cdnUrl + url [ startIndex .. ] , culture ) ;
74
81
}
75
82
76
83
return mediaUrl ;
0 commit comments