canvas_link_migrator 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3b1e71c22b8899f6fe7b5986ee5569fbb9525c0d4cb9e6eb25c9f6ef1804435
4
- data.tar.gz: ba9a4fc3a6ce17be40afab0814818fa7b62603e2aee6d6e5e784110c3fb975c0
3
+ metadata.gz: 69ea954296733466368b26038c4408f864cb840c758591a3129a5cb0c2970a96
4
+ data.tar.gz: 4bb90f2745274adfe514bd22ff321a2ec62dafd379b6ad3cb90aff739c2a8fee
5
5
  SHA512:
6
- metadata.gz: 191de3ba56873baa45d3f922f7276edcdc0f84eda77fc6627cb9d55e4058b00ec792785b08ad4ef666dd4c0efe95b9cdde289320293466dc598d9a703c3532a8
7
- data.tar.gz: 4462eb3f2b424ac381ba35a0f9369c2a671d47efdcb7ac9698ebfeeedccaed397e0736f4d321ba366d9620f7734a9aa69621aba128c47a5a317c6559476ae86d
6
+ metadata.gz: 26f74e87e3e4a5240d7e0de8782d429d0e194ac311d9453ae636b7cbe114bfdb5fda2948b3c6fd135f462cd5a59369406e3eb908e595b4ab0a1669eb45f536e0
7
+ data.tar.gz: 31a6317ec5d8fdd8ba524713a5f71ad948740ce6ae27e5f35b3691a78222efeb04a25cf8c127b4c76791e01588831e9df96dc3deea60a2485d31b4d342d7aed8
@@ -210,7 +210,9 @@ module CanvasLinkMigrator
210
210
  migration_id: $1,
211
211
  rest: $2,
212
212
  in_media_iframe: attr == "src" && ["iframe", "source"].include?(node.name) && node["data-media-id"],
213
- media_attachment: media_attachment)
213
+ media_attachment: media_attachment,
214
+ target_blank: node['target'] == "_blank" && node.name == "a" && attr == "href"
215
+ )
214
216
  elsif url =~ %r{(?:\$CANVAS_OBJECT_REFERENCE\$|\$WIKI_REFERENCE\$)/([^/]*)/([^?]*)(\?.*)?}
215
217
  if KNOWN_REFERENCE_TYPES.include?($1)
216
218
  unresolved(:object, type: $1, migration_id: $2, query: $3)
@@ -116,13 +116,14 @@ module CanvasLinkMigrator
116
116
  when :file_ref
117
117
  file_id = @migration_id_converter.convert_attachment_migration_id(link[:migration_id])
118
118
  if file_id
119
- rest = link[:rest].presence || "/preview"
119
+ rest = link[:rest].presence
120
+ rest ||= "/preview" unless link[:target_blank]
120
121
 
121
122
  # Icon Maker files should not have the course
122
123
  # context prepended to the URL. This prevents
123
124
  # redirects to non cross-origin friendly urls
124
125
  # during a file fetch
125
- if rest.include?("icon_maker_icon=1")
126
+ if rest&.include?("icon_maker_icon=1")
126
127
  link[:new_value] = "/files/#{file_id}#{rest}"
127
128
  elsif link[:in_media_iframe] && link[:media_attachment]
128
129
  link[:new_value] = "/media_attachments_iframe/#{file_id}#{rest}"
@@ -1,3 +1,3 @@
1
1
  module CanvasLinkMigrator
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -29,6 +29,12 @@ describe CanvasLinkMigrator::LinkParser do
29
29
  end
30
30
 
31
31
  describe "convert_link" do
32
+ it "marks target=_blank anchor tags" do
33
+ doc = Nokogiri::HTML5.fragment("<a target=\"_blank\"></a>")
34
+ parsed = parser.parse_url("$CANVAS_COURSE_REFERENCE$/file_ref/whatevs", doc.at_css('a'), "href")
35
+ expect(parsed[:target_blank]).to be true
36
+ end
37
+
32
38
  it "converts inner html of anchor tags when appropriate" do
33
39
  doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/1</a>")
34
40
  parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
@@ -51,6 +51,12 @@ describe CanvasLinkMigrator::LinkResolver do
51
51
  expect(link[:new_value]).to eq("/courses/2/files/6/preview")
52
52
  end
53
53
 
54
+ it "does not suffix /preview to target blank links" do
55
+ link = { link_type: :file_ref, target_blank: true, migration_id: "F" }
56
+ resolver.resolve_link!(link)
57
+ expect(link[:new_value]).to eq("/courses/2/files/6")
58
+ end
59
+
54
60
  it "converts attachment urls" do
55
61
  link = { link_type: :object, type: "attachments", migration_id: "E", query: "?foo=bar" }
56
62
  resolver.resolve_link!(link)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_link_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mysti Lilla
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2024-02-01 00:00:00.000000000 Z
14
+ date: 2024-02-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport