Bug 86087 - FILESAVE FILEOPEN VIEWING: Can't open or save relative links in docx
Summary: FILESAVE FILEOPEN VIEWING: Can't open or save relative links in docx
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium major
Assignee: Szymon Kłos
URL:
Whiteboard: target:5.3.0 target:6.0.0
Keywords: filter:docx
Depends on:
Blocks: DOCX
  Show dependency treegraph
 
Reported: 2014-11-10 03:28 UTC by lameventanas
Modified: 2019-08-02 09:01 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
Error message when opening relative link (20.27 KB, image/png)
2014-11-10 03:28 UTC, lameventanas
Details
test documents with absolute and relative links in LibreOffice and MS Office (13.38 KB, application/x-tar)
2014-11-10 07:30 UTC, lameventanas
Details
Archive contains linked documents using a relative path (25.92 KB, application/x-rar)
2014-12-22 12:12 UTC, eeedgaras
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lameventanas 2014-11-10 03:28:32 UTC
Created attachment 109182 [details]
Error message when opening relative link

I want to use relative links in Writer (open and save them between LibreOffice and MS Word).

I have enabled the option Load/Save -> General -> Save URLs relative to filesystem.

If I insert a link to an external file in the same directory, it is saved as an absolute link (full path).

If I create a document in MS Office 2010, and insert a relative link, LibreOffice Writer can't open it, but MS Office can (see attached screenshot).

I have tried this with PNG and XLS external files in the same directory.
Comment 1 lameventanas 2014-11-10 03:35:41 UTC
Just updated to version 4.2.6.3, same issue.
Comment 2 Jean-Baptiste Faure 2014-11-10 04:59:58 UTC
PLease explain step by step what you do to reproduce the problem, especially how you insert a relative link. And attach your test document.

Best regards. JBF
Comment 3 lameventanas 2014-11-10 07:30:44 UTC
Created attachment 109192 [details]
test documents with absolute and relative links in LibreOffice and MS Office
Comment 4 lameventanas 2014-11-10 07:31:12 UTC
(In reply to Jean-Baptiste Faure from comment #2)
> PLease explain step by step what you do to reproduce the problem, especially
> how you insert a relative link. And attach your test document.


1. Start with a brand new configuration for LibreOffice in Linux:
mkdir ~/bak
mv ~/.libreoffice ~/libreoffice ~/bak
mv ~/.config/libreoffice ~/bak/config

2. Create a "test" directory:
mkdir ~/test
cd ~/test

3. Create a pair of files to link in the document:
echo relative > relative.txt
echo absolute > absolute.txt

4. Verify that my distribution didn't create some strange shellscript wrapper (I already know this because I checked how the package was created):

bash$ ls -l /usr/bin/soffice
lrwxrwxrwx 1 root root 36 Nov 10 12:20 /usr/bin/soffice -> /usr/lib/libreoffice/program/soffice

bash$ md5sum /usr/lib/libreoffice/program/soffice
ec0d407981b993c828024639cefebda7  /usr/lib/libreoffice/program/soffice

bash$ head /usr/lib/libreoffice/program/soffice
#!/bin/sh
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#

5. Start LibreOffice Writer by running in bash:
soffice

6. Verify settings in Tools / Options / Load/Save / General.  Save URLs relative to file system is checked by default.

7. Click on "Writer Document" to create a Writer document.

8. Insert a link (CTRL-K)

9. Click on "Document" to insert a link to a local file, rather than an Internet link

10. Type in the "Document Path" field:
relative.txt

11. Click [Apply]

12. A link is created:
text: "relative.txt"
tooltip: "Control-Click to follow link: relative.txt"

13. Hit <enter> to insert newlines a couple of times, and then a new link (CTRL-K)

14. Click on the Filesystem browser icon, next to the "Document Path" field.

15. Browse the filesystem to select ~/test/absolute.txt

16. Click [Apply]

17. A link is created:
text: "/home/alan/test/absolute.txt"
tooltip: "Control-Click to follow link: file:///home/alan/test/absolute.txt"

18. Current situation:
	a. the document has not been saved
	b. the current working directory of soffice is /home/alan/test:
		bash$ pgrep -a soffice
		1222 /usr/lib/libreoffice/program/soffice.bin --splash-pipe=5
		bash$ ls -l /proc/1222/cwd
		lrwxrwxrwx 1 alan users 0 Nov 10 16:00 /proc/1222/cwd -> /home/alan/test

19. Control-Click the first link (relative.txt).  You will get an error message.

20. Control-Click the second link (/home/alan/test/absolute.txt).  The file will open with an external program.

21. Save (CTRL-S)

22. In the file-save dialog, browse to ~/test and save as test-lo.docx

23. A new window pops, saying:
This document may contain formatting or content that cannot be saved in the currently selected file format "Microsoft Word 2007/2010/2013 XML".
Use the default ODF file format to be sure that the document is saved correctly.
[x] Ask when not saving in ODF format
[Use Microsoft Word 2007/2010/2013 XML Format] [Use ODF Format]

24. Click on "Use Microsoft Word 2007/2010/2013 XML Format"

25. Close LibreOffice Writer

26. Go to a Windows computer with MS Office 2010

27. Create a new directory: c:\temp\test

28. Copy the ~/test directory from the Linux computer to Windows, under c:\temp

29. Go to c:\temp\test, double click test-lo.docx, it opens in MS Word 2010, the title bar shows: test-lo.docx [Compatibility Mode].  The document in MS Word shows the text "/tmp/test.txt", the popup shows:
file:///\\tmp\test.txt
Ctrl+Click to follow link

30. Move the pointer over the text.  There is no popup for the first text (relative.txt), but there is a popup for the second one (/home/alan/test/absolute.txt).  The first text is not even a link.  The link was lost when LibreOffice saved the file.
 
31. Press Ctrl while clicking the absolute link, an error message shows up saying:
Cannot open the specified file.  This is expected.

32. Click on File / Close to close the current document

33. Click on File / New / Blank document to create a new document

34. Click on Insert / Hyperlink

35. Type "relative.txt" in the Address field.

36. A link is created:
text: "relative.txt"
tooltip: "Control-Click to follow link: relative.txt"

37. Hit enter to insert a newline, and then click on Insert / Hyperlink

38. Click on the Filesystem browser icon, next to the "Document Path" field.

39. Browse the filesystem to select c:\temp\test\absolute.txt

40. Click [OK]

41. A link is created:
text: "C:\temp\test\absolute.txt"
tooltip: "Ctrl-Click to follow link: file:///c:\temp\test\absolute.txt"

42. Current situation:
	a. the document has not been saved
	b. the current working directory of MS Office is unknown

43. Control-click the first link (relative.txt).  You will get an error message.

44. Control-click the second link (c:\temp\test\absolute.txt).  After a warning dialog, the file will open with an external program.

45. Save (CTRL-S)

46. Type "c:\temp\test\test-ms.docx" and click [Save]

47. Control-click the first link again (relative.txt).  This time it opens.

48. Close MS Word

49. Copy test-ms.docx saved by MS Word with the relative link to the Linux computer, to ~/test/

50. Open test-ms.docx with LibreOffice

51. Control-Click the first link (relative.txt).  You will get an error message (this is an error).

52. Control-Click the first link (c:\temp\test\absolute.txt).  You will get an error message (this is expected).
Comment 5 Jean-Baptiste Faure 2014-11-11 16:35:03 UTC
Thank you for your answer. Setting back to unconfirmed. Can't test your scenario myself because I do not have MS-Windows.

Best regards. JBF
Comment 6 lameventanas 2014-11-12 00:12:17 UTC
(In reply to Jean-Baptiste Faure from comment #5)
> Thank you for your answer. Setting back to unconfirmed. Can't test your
> scenario myself because I do not have MS-Windows.

Reproducing this bug doesn't require Windows.

This bug report could be divided in two:

1. LibreOffice in Linux can't create a document with relative links.
2. LibreOffice in Linux can't open relative links.

Since I can't create a document with relative links in LibreOffice in Linux, I had to use MS Office to create one, and then prove the second bug.

You don't need Windows to reproduce the first bug, and you don't need Windows to reproduce the second bug since I have attached a document with relative links created by MS Office.
Comment 7 Cor Nouws 2014-12-21 21:01:57 UTC
Hi lameventanas,

(In reply to lameventanas from comment #6)

> 1. LibreOffice in Linux can't create a document with relative links.
> 2. LibreOffice in Linux can't open relative links.


This simply works for me on Ubuntu with 4.2.x .. 4.4.x (and in the past too, from what I know)..
Comment 8 eeedgaras 2014-12-22 12:10:16 UTC
I have the same problem - relative links to files does not work.

== General Info
OS: Both on Linux and Win7. 
LibreOffice: Version: 4.3.5.2

== Steps
See new attachment "test_relative_path.rar" which contains the example.
1) Extract all contents of archive in any location
2) Open "test_out.docx" with LibreOffice
3) Click "Relative File Link" in the document
4) File "linked.docx" that resides in "test_out_files" directory is not oppened. It is considered to be an absolute path, though it is of relative form

== Additional info
MS Office handles this relative link and file "linked.docx" is opened.
The link contains this text: {HYPERLINK "test_out_files/linked.docx"}
We generate .doxc documents automatically and what we are trying to achieve is that if 1st user generates document + document's resources in subfolder and sends all the files to 2nd user, then 2nd user could navigate to the resource files on their machine.
Comment 9 eeedgaras 2014-12-22 12:12:32 UTC
Created attachment 111177 [details]
Archive contains linked documents using a relative path
Comment 10 Buovjaga 2015-01-13 09:52:44 UTC
(In reply to eeedgaras from comment #8)
> == Steps
> See new attachment "test_relative_path.rar" which contains the example.
> 1) Extract all contents of archive in any location
> 2) Open "test_out.docx" with LibreOffice
> 3) Click "Relative File Link" in the document
> 4) File "linked.docx" that resides in "test_out_files" directory is not
> oppened. It is considered to be an absolute path, though it is of relative
> form

Reproduced.

Not working on 3.3.0 either, launched from soffice.sh:
sh: 1: test_out_files/linked.docx: not found

Ubuntu 14.10 64-bit Version: 4.5.0.0.alpha0+
Build ID: 7201fa0dddd7dd0352f69fd2b2b64efcb361ccad
TinderBox: Linux-rpm_deb-x86_64@46-TDF-dbg, Branch:master, Time: 2015-01-11_23:28:55

LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-3.3.0.4

Win 7 64-bit Version: 4.5.0.0.alpha0+
Build ID: b3b4bbaf6cbd2226b659fea7d6ae473ccf84e9dd
TinderBox: Win-x86@39, Branch:master, Time: 2015-01-12_06:13:44
Comment 11 QA Administrators 2016-01-17 20:02:33 UTC Comment hidden (obsolete)
Comment 12 dE 2016-07-10 11:12:17 UTC
Bug is still present in 5.1.2.2.0 and it does not work with images too.
Comment 13 Stephan Bergmann 2016-08-16 15:53:41 UTC
So this is apparently a problem with docx (and probably similar formats) only, not with odt.
Comment 14 Stephan Bergmann 2016-08-17 11:45:11 UTC
<https://cgit.freedesktop.org/libreoffice/core/commit/?id=0dd82f4ffe7ae462bae30b93d245d2234c55ef84> "tdf#86087: Convert relative URLs to absolute upon import of docx etc." fixes the import part of the issue.
Comment 15 dE 2017-05-14 11:59:41 UTC
(In reply to Stephan Bergmann from comment #13)
> So this is apparently a problem with docx (and probably similar formats)
> only, not with odt.

No, this's a problem with ODT also. This also effect HTML exports. The HTML cannot refer relative links.

Documents getting bigger. Save times increasing...
Comment 16 dE 2017-05-14 12:01:08 UTC
(In reply to Stephan Bergmann from comment #14)
> <https://cgit.freedesktop.org/libreoffice/core/commit/
> ?id=0dd82f4ffe7ae462bae30b93d245d2234c55ef84> "tdf#86087: Convert relative
> URLs to absolute upon import of docx etc." fixes the import part of the
> issue.

This has to be reverted back! This's a bug in itself! LO must support relative links.
Comment 17 Stephan Bergmann 2017-05-16 11:52:54 UTC
(In reply to dE from comment #15)
> (In reply to Stephan Bergmann from comment #13)
> > So this is apparently a problem with docx (and probably similar formats)
> > only, not with odt.
> 
> No, this's a problem with ODT also. This also effect HTML exports. The HTML
> cannot refer relative links.
> 
> Documents getting bigger. Save times increasing...

No idea what your exact problem with HTML export is.  Please file a new bug (and mention its ID here) clearly stating the exact problem with HTML export.
Comment 18 Stephan Bergmann 2017-05-16 11:53:41 UTC
(In reply to dE from comment #16)
> (In reply to Stephan Bergmann from comment #14)
> > <https://cgit.freedesktop.org/libreoffice/core/commit/
> > ?id=0dd82f4ffe7ae462bae30b93d245d2234c55ef84> "tdf#86087: Convert relative
> > URLs to absolute upon import of docx etc." fixes the import part of the
> > issue.
> 
> This has to be reverted back! This's a bug in itself! LO must support
> relative links.

What exactly is it that stopped working with that commit?  Please be precise.
Comment 19 Commit Notification 2017-11-19 17:17:59 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=4b9e237850efe36f7e35d65e14d6953f1e1f3a45

tdf#86087 Open relative links in Writer

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Commit Notification 2017-11-19 20:16:14 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=40acf8d6447065077acba9e800c56239f58c8262

tdf#86087 DOCX Import link as relative if preferred

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 21 Commit Notification 2017-11-19 20:16:23 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=2b2f1352c72280dd25ed3bef090a3c708ee4b964

tdf#86087 Save relative links in DOCX

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 22 Commit Notification 2017-11-21 08:07:58 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=30af6599d59067a8da6dc4075e80069e80e25f09

tdf#86087 don't decode links

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 23 Commit Notification 2017-11-22 09:09:57 UTC
Szymon Kłos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=fd51f01dbca1ddebe846ec9f56cbb13002f295c6

tdf#86087 fix relative link open on linux

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.