canvas_link_migrator 1.0.1 → 1.0.3

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: 7d147093c7e6b397c3eb184aba4af1595f782e14735a50e9d4986be628af75f3
4
- data.tar.gz: cb48c35f35dd333b02ff7dcba5e3bd79d1a1a7b736b7bb14c56de11b6c91565e
3
+ metadata.gz: 68ad9b1c1c452ba59ce56cae7ec072c38c185a4b5e4e3457082d8356dc95cd95
4
+ data.tar.gz: cc85f34cf8cb4abdb812d6582f213371afc6ccfd0a8ca6bb11f6152367d3d359
5
5
  SHA512:
6
- metadata.gz: 4074cbb1bfa20b00f4843327d62ee0e1cf739f7450b46698ee1a6a240054f27acd34046605e2ae4f54bbdf02b529272ba165769352e10abff1f5950c08af6ad8
7
- data.tar.gz: e1deecf7b1d6586c432234092e338c9d3059f26b744072eab1cb6e644c25dbcec9ffacfb53239b6c9ffc0610c210bf80399f097f2d7efa2265686caf314a8fee
6
+ metadata.gz: 8c8c85af3a7357591b9f07ddae0c98649c72880fc134c56cdafb20deb5083d2379020b7c459b191beeb4973f8fab878c831fb39b801b4249f4f8d1407eaec040
7
+ data.tar.gz: eded5e2885a8e3be4c22a2878c75e7ad889621f5a0f2bc4b57242656e5800aab0ad87d1ce5d18185b4080c1526f50382b81c49330feb74bf3d90925926cdbea3
@@ -129,7 +129,12 @@ module CanvasLinkMigrator
129
129
  url.gsub!("%24#{ref}%24", "$#{ref}$")
130
130
  end
131
131
 
132
- result = parse_url(url, node, attr)
132
+ begin
133
+ result = parse_url(url, node, attr)
134
+ rescue Addressable::URI::InvalidURIError
135
+ return
136
+ end
137
+
133
138
  if result[:resolved]
134
139
  # resolved, just replace and carry on
135
140
  new_url = result[:new_url] || url
@@ -166,6 +171,10 @@ module CanvasLinkMigrator
166
171
  else
167
172
  result[:old_value] = node[attr]
168
173
  result[:placeholder] = placeholder(result[:old_value])
174
+ # replace the inner html of an anchor tag if it matches the href
175
+ if node.name == "a" && attr == "href" && node["href"] == node.inner_html.delete("\n").strip
176
+ node.inner_html = result[:placeholder]
177
+ end
169
178
  node[attr] = result[:placeholder]
170
179
  end
171
180
  add_unresolved_link(result, item_type, mig_id, field)
@@ -177,7 +186,7 @@ module CanvasLinkMigrator
177
186
  end
178
187
 
179
188
  def resolved(new_url = nil)
180
- { resolved: true, new_url: new_url }
189
+ { resolved: true, new_url: new_url}
181
190
  end
182
191
 
183
192
  # returns a hash with resolution status and data to hold onto if unresolved
@@ -186,7 +195,7 @@ module CanvasLinkMigrator
186
195
  query_values = parsed_url.query_values
187
196
  media_attachment = query_values.try(:delete, "media_attachment") == "true"
188
197
  if media_attachment
189
- parsed_url.query_values = query_values.present? ? query_values : nil
198
+ parsed_url.query_values = query_values.presence || nil
190
199
  url = Addressable::URI.unencode(parsed_url)
191
200
  end
192
201
 
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (C) 2023 - present Instructure, Inc.
5
+ #
6
+ # This file is part of Canvas.
7
+ #
8
+ # Canvas is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Affero General Public License as published by the Free
10
+ # Software Foundation, version 3 of the License.
11
+ #
12
+ # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
13
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
+ # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
15
+ # details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License along
18
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require "spec_helper"
22
+
23
+ describe CanvasLinkMigrator::LinkParser do
24
+ def parser
25
+ migration_query_service_mock = double()
26
+ allow(migration_query_service_mock).to receive(:supports_embedded_images).and_return(true)
27
+ allow(migration_query_service_mock).to receive(:fix_relative_urls?).and_return(true)
28
+ CanvasLinkMigrator::LinkParser.new(migration_query_service_mock)
29
+ end
30
+
31
+ describe "convert_link" do
32
+ it "converts inner html of anchor tags when appropriate" do
33
+ doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/1</a>")
34
+ parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
35
+ expect(doc.at_css('a')['href']).to include("LINK.PLACEHOLDER")
36
+ expect(doc.at_css('a').inner_html).to include("LINK.PLACEHOLDER")
37
+ end
38
+
39
+ it "doesn't convert inner html of anchor tags if unnecessary" do
40
+ doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/5</a>")
41
+ parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
42
+ expect(doc.at_css('a')['href']).to include("LINK.PLACEHOLDER")
43
+ expect(doc.at_css('a').inner_html).not_to include("LINK.PLACEHOLDER")
44
+ end
45
+
46
+ it "doesn't convert inner html of anchor tags if unnecessary" do
47
+ doc = Nokogiri::HTML5.fragment("<a href=\"https://what:10.1111/HFP.0b013e31828df26\">broken link</a>")
48
+ expect{ parser.convert_link(doc.at_css('a'), "href", "wiki_page", "migrationid", "") }.not_to raise_error
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_link_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mysti Lilla
8
8
  - James Logan
9
9
  - Sarah Gerard
10
+ - Math Costa
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2023-11-04 00:00:00.000000000 Z
14
+ date: 2024-01-29 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: activesupport
@@ -129,6 +130,7 @@ email:
129
130
  - mysti@instructure.com
130
131
  - james.logan@instructure.com
131
132
  - sarah.gerard@instructure.com
133
+ - luis.oliveira@instructure.com
132
134
  executables: []
133
135
  extensions: []
134
136
  extra_rdoc_files: []
@@ -141,6 +143,7 @@ files:
141
143
  - lib/canvas_link_migrator/resource_map_service.rb
142
144
  - lib/canvas_link_migrator/version.rb
143
145
  - spec/canvas_link_migrator/imported_html_converter_spec.rb
146
+ - spec/canvas_link_migrator/link_parser_spec.rb
144
147
  - spec/canvas_link_migrator/link_resolver_spec.rb
145
148
  - spec/canvas_link_migrator_spec.rb
146
149
  - spec/fixtures/canvas_resource_map.json