qti 2.7.1 → 2.8.0
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 +4 -4
 - data/lib/qti/sanitizer.rb +13 -0
 - data/lib/qti/version.rb +1 -1
 - data/lib/qti.rb +9 -0
 - data/spec/fixtures/items_1.2/true_false.xml +1 -1
 - data/spec/lib/qti/v1/models/assessment_item_spec.rb +12 -0
 - data/spec/spec_helper.rb +4 -0
 - metadata +7 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e121df522dfdc1e21c2944bfa04334fdb4226c8a288356ff4ad1ef84e7354a86
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 01cea5632a13762bc2929b4f61cafbc47893c38fda88c1d14a5d51a5eb1b73aa
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 43eb6eee2a5e6073750023429875e267565ab4ff2a23a6bcf292231ccf95f5a09da886208d12ad1fc4db7c339616801e908b0c0a4e3aee0c72f4e651065eaec3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cfea73f7c7d3a86f41de834205c634a5f0789ea57519eb180491a8411c55e292c4648673ca76d5aa1b04653ee7e704de50a422b3399780f3f428301a897d2968
         
     | 
    
        data/lib/qti/sanitizer.rb
    CHANGED
    
    | 
         @@ -37,6 +37,18 @@ module Qti 
     | 
|
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                private
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
                def convert_canvas_math_images(env)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  node = env[:node]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  node_name = env[:node_name]
         
     | 
| 
      
 43 
     | 
    
         
            +
                  latex = node['data-equation-content']
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  return if env[:is_whitelisted] || !env[:node].element?
         
     | 
| 
      
 46 
     | 
    
         
            +
                  return unless node_name == 'img'
         
     | 
| 
      
 47 
     | 
    
         
            +
                  return unless latex
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  node.replace("\\(#{latex}\\)")
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       40 
52 
     | 
    
         
             
                def object_tag_transformer
         
     | 
| 
       41 
53 
     | 
    
         
             
                  lambda do |env|
         
     | 
| 
       42 
54 
     | 
    
         
             
                    return unless env[:node_name] == 'object'
         
     | 
| 
         @@ -73,6 +85,7 @@ module Qti 
     | 
|
| 
       73 
85 
     | 
    
         
             
                  transformers << src_transformers
         
     | 
| 
       74 
86 
     | 
    
         
             
                  transformers << object_tag_transformer if import_objects
         
     | 
| 
       75 
87 
     | 
    
         
             
                  transformers << remap_unknown_tags_transformer
         
     | 
| 
      
 88 
     | 
    
         
            +
                  transformers << method(:convert_canvas_math_images) if Qti.configuration.extract_latex_from_image_tags
         
     | 
| 
       76 
89 
     | 
    
         
             
                  Sanitize::Config::RELAXED.merge transformers: transformers
         
     | 
| 
       77 
90 
     | 
    
         
             
                end
         
     | 
| 
       78 
91 
     | 
    
         | 
    
        data/lib/qti/version.rb
    CHANGED
    
    
    
        data/lib/qti.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ require 'active_support/core_ext/string' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'active_support/core_ext/hash/except'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'active_support/core_ext/module/delegation'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'dry-struct'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'ostruct'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'find'
         
     | 
| 
       8 
9 
     | 
    
         
             
            require 'forwardable'
         
     | 
| 
       9 
10 
     | 
    
         
             
            require 'mathml2latex'
         
     | 
| 
         @@ -68,6 +69,14 @@ module Qti 
     | 
|
| 
       68 
69 
     | 
    
         
             
                  @import.create_question_group(question_group_ref)
         
     | 
| 
       69 
70 
     | 
    
         
             
                end
         
     | 
| 
       70 
71 
     | 
    
         
             
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              def self.configuration
         
     | 
| 
      
 74 
     | 
    
         
            +
                @configuration ||= OpenStruct.new
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              def self.configure
         
     | 
| 
      
 78 
     | 
    
         
            +
                yield(configuration)
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
       71 
80 
     | 
    
         
             
            end
         
     | 
| 
       72 
81 
     | 
    
         | 
| 
       73 
82 
     | 
    
         
             
            # The load order of all of these is important.
         
     | 
| 
         @@ -5,7 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         
             
                  <item title="Grading - specific - 3 pt score" ident="QUE_1003">
         
     | 
| 
       6 
6 
     | 
    
         
             
                    <presentation>
         
     | 
| 
       7 
7 
     | 
    
         
             
                      <material>
         
     | 
| 
       8 
     | 
    
         
            -
                        <mattext texttype="text/html"><![CDATA[If I get a 3, I must have done something wrong. <img align="bottom" alt="image.png" src="org0/images/image.png" border="0"/>]]></mattext>
         
     | 
| 
      
 8 
     | 
    
         
            +
                        <mattext texttype="text/html"><![CDATA[If I get a 3, I must have done something wrong. <img data-equation-content="sample equation" script="alert('bad')" align="bottom" alt="image.png" src="org0/images/image.png" border="0"/> <img script="alert('bad')" align="bottom" alt="image.png" src="org0/images/image.png" border="0"/>]]></mattext>
         
     | 
| 
       9 
9 
     | 
    
         
             
                      </material>
         
     | 
| 
       10 
10 
     | 
    
         
             
                      <response_lid ident="QUE_1004_RL" rcardinality="Single" rtiming="No">
         
     | 
| 
       11 
11 
     | 
    
         
             
                        <render_choice shuffle="Yes">
         
     | 
| 
         @@ -29,6 +29,18 @@ describe Qti::V1::Models::AssessmentItem do 
     | 
|
| 
       29 
29 
     | 
    
         
             
                it 'has sanitized item_body' do
         
     | 
| 
       30 
30 
     | 
    
         
             
                  expect(loaded_class.item_body).to include '<img'
         
     | 
| 
       31 
31 
     | 
    
         
             
                  expect(loaded_class.item_body).to include 'If I get a 3, I must have done something wrong.'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  expect(loaded_class.item_body).not_to include 'script="alert(\'bad\')"'
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                it 'transforms canvas math content when conversion is enabled' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  expect(loaded_class.item_body).to include '\(sample equation\)'
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                it 'does not transform math content when conversion is Disabled' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Qti.configure do |config|
         
     | 
| 
      
 41 
     | 
    
         
            +
                    config.extract_latex_from_image_tags = false
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                  expect(loaded_class.item_body).not_to include '"sample equation"'
         
     | 
| 
       32 
44 
     | 
    
         
             
                end
         
     | 
| 
       33 
45 
     | 
    
         | 
| 
       34 
46 
     | 
    
         
             
                describe '#points_possible' do
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -16,6 +16,10 @@ end 
     | 
|
| 
       16 
16 
     | 
    
         
             
            $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
         
     | 
| 
       17 
17 
     | 
    
         
             
            require 'qti'
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
      
 19 
     | 
    
         
            +
            Qti.configure do |config|
         
     | 
| 
      
 20 
     | 
    
         
            +
              config.extract_latex_from_image_tags = true
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       19 
23 
     | 
    
         
             
            Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
         
     | 
| 
       20 
24 
     | 
    
         | 
| 
       21 
25 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,15 +1,15 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: qti
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.8.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Hannah Bottalla
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Robinson Rodríguez
         
     | 
| 
       9 
     | 
    
         
            -
            autorequire:
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2022-01-18 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: actionview
         
     | 
| 
         @@ -275,7 +275,7 @@ dependencies: 
     | 
|
| 
       275 
275 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       276 
276 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       277 
277 
     | 
    
         
             
                    version: '1.4'
         
     | 
| 
       278 
     | 
    
         
            -
            description:
         
     | 
| 
      
 278 
     | 
    
         
            +
            description: 
         
     | 
| 
       279 
279 
     | 
    
         
             
            email:
         
     | 
| 
       280 
280 
     | 
    
         
             
            - hannah@instructure.com
         
     | 
| 
       281 
281 
     | 
    
         
             
            - rrodriguez-bd@instructure.com
         
     | 
| 
         @@ -684,7 +684,7 @@ homepage: https://github.com/instructure/qti 
     | 
|
| 
       684 
684 
     | 
    
         
             
            licenses:
         
     | 
| 
       685 
685 
     | 
    
         
             
            - MIT
         
     | 
| 
       686 
686 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       687 
     | 
    
         
            -
            post_install_message:
         
     | 
| 
      
 687 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
       688 
688 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       689 
689 
     | 
    
         
             
            require_paths:
         
     | 
| 
       690 
690 
     | 
    
         
             
            - lib
         
     | 
| 
         @@ -699,8 +699,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       699 
699 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       700 
700 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       701 
701 
     | 
    
         
             
            requirements: []
         
     | 
| 
       702 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
       703 
     | 
    
         
            -
            signing_key:
         
     | 
| 
      
 702 
     | 
    
         
            +
            rubygems_version: 3.0.3
         
     | 
| 
      
 703 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
       704 
704 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       705 
705 
     | 
    
         
             
            summary: QTI 1.2 and 2.1 import and export models
         
     | 
| 
       706 
706 
     | 
    
         
             
            test_files:
         
     |