mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
Merge pull request #1913 from anyproto/go-4574-importing-markdown-file-that-contains-broken-link-makes-app
GO-4574 importing markdown file that contains broken link makes app crash
This commit is contained in:
commit
efa8c8ddf2
3 changed files with 41 additions and 5 deletions
|
@ -125,7 +125,7 @@ func (m *mdConverter) handleSingleMark(block *model.Block, files map[string]*Fil
|
|||
}
|
||||
file.HasInboundLinks = true
|
||||
} else if wholeLineLink {
|
||||
block.Content = m.convertTextToBookmark(txt.Marks.Marks[0].Param)
|
||||
m.convertTextToBookmark(txt.Marks.Marks[0].Param, block)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ func (m *mdConverter) handleSingleLinkMark(block *model.Block, files map[string]
|
|||
return true
|
||||
}
|
||||
} else if m.isWholeLineLink(txt.Text, mark) {
|
||||
block.Content = m.convertTextToBookmark(mark.Param)
|
||||
m.convertTextToBookmark(mark.Param, block)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -238,12 +238,12 @@ func (m *mdConverter) convertTextToPageLink(block *model.Block) {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *mdConverter) convertTextToBookmark(url string) *model.BlockContentOfBookmark {
|
||||
func (m *mdConverter) convertTextToBookmark(url string, block *model.Block) {
|
||||
if err := uri.ValidateURI(url); err != nil {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
return &model.BlockContentOfBookmark{
|
||||
block.Content = &model.BlockContentOfBookmark{
|
||||
Bookmark: &model.BlockContentBookmark{
|
||||
Url: url,
|
||||
},
|
||||
|
|
|
@ -146,6 +146,7 @@ func buildExpectedTree(fileNameToObjectId map[string]string, provider *MockTempD
|
|||
testMdPath := filepath.Join("testdata", "test.md")
|
||||
testCsvPath := filepath.Join("testdata", "test.csv")
|
||||
testTxtPath := filepath.Join("testdata", "test.txt")
|
||||
url := "http://example.com/%zz"
|
||||
want := blockbuilder.Root(
|
||||
blockbuilder.ID(rootId),
|
||||
blockbuilder.Children(
|
||||
|
@ -171,6 +172,13 @@ func buildExpectedTree(fileNameToObjectId map[string]string, provider *MockTempD
|
|||
Param: fileNameToObjectId[testCsvPath],
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Text("Should not panic test5", blockbuilder.TextMarks(model.BlockContentTextMarks{Marks: []*model.BlockContentTextMark{
|
||||
{
|
||||
Range: &model.Range{From: 17, To: 22},
|
||||
Type: model.BlockContentTextMark_Link,
|
||||
Param: url,
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Text("File does not exist with bold mark test1", blockbuilder.TextMarks(model.BlockContentTextMarks{Marks: []*model.BlockContentTextMark{
|
||||
{
|
||||
Range: &model.Range{From: 35, To: 40},
|
||||
|
@ -215,6 +223,17 @@ func buildExpectedTree(fileNameToObjectId map[string]string, provider *MockTempD
|
|||
Type: model.BlockContentTextMark_Bold,
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Text("Should not panic test5", blockbuilder.TextMarks(model.BlockContentTextMarks{Marks: []*model.BlockContentTextMark{
|
||||
{
|
||||
Range: &model.Range{From: 17, To: 22},
|
||||
Type: model.BlockContentTextMark_Link,
|
||||
Param: url,
|
||||
},
|
||||
{
|
||||
Range: &model.Range{From: 17, To: 22},
|
||||
Type: model.BlockContentTextMark_Bold,
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Bookmark(fileMdPath),
|
||||
blockbuilder.Text("test2", blockbuilder.TextMarks(model.BlockContentTextMarks{Marks: []*model.BlockContentTextMark{
|
||||
{
|
||||
|
@ -239,6 +258,17 @@ func buildExpectedTree(fileNameToObjectId map[string]string, provider *MockTempD
|
|||
Type: model.BlockContentTextMark_Bold,
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Text("test5", blockbuilder.TextMarks(model.BlockContentTextMarks{Marks: []*model.BlockContentTextMark{
|
||||
{
|
||||
Range: &model.Range{From: 0, To: 5},
|
||||
Type: model.BlockContentTextMark_Link,
|
||||
Param: url,
|
||||
},
|
||||
{
|
||||
Range: &model.Range{From: 0, To: 5},
|
||||
Type: model.BlockContentTextMark_Bold,
|
||||
},
|
||||
}})),
|
||||
blockbuilder.Link(rootId),
|
||||
))
|
||||
return want
|
||||
|
|
6
core/block/import/markdown/testdata/links.md
vendored
6
core/block/import/markdown/testdata/links.md
vendored
|
@ -6,6 +6,8 @@ Test file block [test3](test.txt)
|
|||
|
||||
Test link to csv [test4](test.csv)
|
||||
|
||||
Should not panic [test5](http://example.com/%zz)
|
||||
|
||||
File does not exist with bold mark **[test1](file.md)**
|
||||
|
||||
Test link to page with bold mark **[test2](test.md)**
|
||||
|
@ -14,6 +16,8 @@ Test file block with bold mark **[test3](test.txt)**
|
|||
|
||||
Test link to csv with bold mark **[test4](test.csv)**
|
||||
|
||||
Should not panic **[test5](http://example.com/%zz)**
|
||||
|
||||
**[test1](file.md)**
|
||||
|
||||
**[test2](test.md)**
|
||||
|
@ -21,3 +25,5 @@ Test link to csv with bold mark **[test4](test.csv)**
|
|||
**[test3](test.txt)**
|
||||
|
||||
**[test4](test.csv)**
|
||||
|
||||
**[test5](http://example.com/%zz)**
|
Loading…
Add table
Add a link
Reference in a new issue