Skip to content

Commit f62d5e0

Browse files
committed
Fix recognition of network paths in UrlUtil, add test
DEVSIX-1670
1 parent 8852427 commit f62d5e0

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
using iText.IO.Image;
8+
using iText.Layout.Element;
9+
10+
namespace iText.Layout
11+
{
12+
// This test is present only in c#
13+
class NetWorkPathTest
14+
{
15+
[NUnit.Framework.Test]
16+
public virtual void NetworkPathImageTest()
17+
{
18+
var fullImagePath = @"\\someVeryRandomWords\SomeVeryRandomName.img";
19+
string startOfMsg = null;
20+
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
21+
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
22+
try
23+
{
24+
Image drawing = new Image(ImageDataFactory.Create(fullImagePath));
25+
}
26+
catch (Exception e)
27+
{
28+
if (e.InnerException != null && e.InnerException.Message.Length > 18)
29+
startOfMsg = e.InnerException.Message.Substring(0, 19);
30+
}
31+
NUnit.Framework.Assert.IsNotNull(startOfMsg);
32+
NUnit.Framework.Assert.AreNotEqual("Could not find file", startOfMsg);
33+
}
34+
}
35+
}

itext/itext.io/itext/io/source/RandomAccessSourceFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public IRandomAccessSource CreateSource(FileStream raf)
153153
/// <exception cref="System.IO.IOException"/>
154154
public IRandomAccessSource CreateSource(Uri url) {
155155
#if !NETSTANDARD1_6
156-
WebRequest wr = WebRequest.Create(Uri.UnescapeDataString(url.AbsoluteUri));
156+
WebRequest wr = WebRequest.Create(url.LocalPath);
157157
wr.Credentials = CredentialCache.DefaultCredentials;
158158
Stream isp = wr.GetResponse().GetResponseStream();
159159
#else

itext/itext.io/itext/io/util/UrlUtil.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public static Uri ToURL(String filename) {
7171
public static Stream OpenStream(Uri url) {
7272
Stream isp;
7373
if (url.IsFile) {
74-
isp = new FileStream(Uri.UnescapeDataString(url.AbsolutePath), FileMode.Open, FileAccess.Read);
74+
// do not replace first argument with Uri.UnescapeDataString(url.AbsolutePath) instead of url.LocalPath
75+
// it breaks the recognition of network paths
76+
isp = new FileStream(url.LocalPath, FileMode.Open, FileAccess.Read);
7577
} else {
7678
#if !NETSTANDARD1_6
7779
WebRequest req = WebRequest.Create(url);

0 commit comments

Comments
 (0)