Incorrect output in quiz review when Equation object is present

When viewing a fill_in_multiple_blanks quiz submission which
contains equations the answers aren't displayed in the question box.
This appears to be related to a difference in how the string is
processed when it contains equation objects.

Fixes CNVS-2669

Test Plan:
  - Create a quiz which has a fill_in_multiple_blanks quiz question and
    contains an equation object
  - Answer quiz
  - Confirm that answers are written inline, and that the field is
    readonly

Change-Id: I7c25757d3102c3c2fe38d62d615bbc71d153f756
Reviewed-on: https://gerrit.instructure.com/38986
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Trevor deHaan <tdehaan@instructure.com>
Product-Review: Ryan Taylor <rtaylor@instructure.com>
This commit is contained in:
Ryan Taylor 2014-08-08 18:45:05 -06:00
parent 1277fcea73
commit 0d9affeade
2 changed files with 19 additions and 5 deletions

View File

@ -427,9 +427,9 @@ module QuizzesHelper
answer_list.each do |entry|
entry[:blank_id] = AssessmentQuestion.variable_id(entry[:blank_id])
end
res.gsub! %r{<input.*?name=['"](question_.*?)['"].*?/>} do |match|
res.gsub! %r{<input.*?name=\\?['"](question_.*?)\\?['"].*?>} do |match|
blank = match.match(RE_EXTRACT_BLANK_ID).to_a[1]
blank.gsub!(/\\/,'')
answer = answer_list.detect { |entry| entry[:blank_id] == blank } || {}
answer = h(answer[:answer] || '')
@ -438,11 +438,10 @@ module QuizzesHelper
# Replace the {{question_BLAH}} template text with the user's answer text.
match = match.sub(/\{\{question_.*?\}\}/, answer.to_s).
# Match on "/>" but only when at the end of the string and insert "readonly" if set to be readonly
sub(/\/\>\Z/, readonly_markup)
sub(/\/*>\Z/, readonly_markup)
end
# add labelling to input element regardless
match.sub(/\/\>\Z/, "#{label_attr} />")
match.sub(/\/*>\Z/, "#{label_attr} />")
end
if answer_list.empty?

View File

@ -262,6 +262,21 @@ describe QuizzesHelper do
html.should =~ /aria\-label/
html.should =~ /Fill in the blank/
end
it 'should handle equation img tags in the question text' do
broken_question_text = "\"<p>Rubisco is a <input class='question_input' type='text' autocomplete='off' style='width: 120px;' name=\\\"question_8_26534e6c8737f63335d5d98ca4136d09\\\" value='{{question_8_26534e6c8737f63335d5d98ca4136d09}}' > responsible for the first enzymatic step of carbon <input class='question_input' type='text' autocomplete='off' style='width: 120px;' name='question_8_f8e302199c03689d87c52e942b56e1f4' value='{{question_8_f8e302199c03689d87c52e942b56e1f4}}' >. <br><br>equation here: <img class=\\\"equation_image\\\" title=\\\"\\sum\\frac{k}{l}\\\" src=\\\"/equation_images/%255Csum%255Cfrac%257Bk%257D%257Bl%257D\\\" alt=\\\"\\sum\\frac{k}{l}\\\"></p>\""
@answer_list = [
{ blank_id: 'kindof', answer: 'protein'},
{blank_id: 'role', answer: 'fixing'}
]
html = fill_in_multiple_blanks_question(
question: {question_text: broken_question_text},
answer_list: @answer_list,
answers: @answers
)
html.should =~ /"readonly"/
html.should =~ /value='fixing'/
html.should =~ /value='protein'/
end
end
context "multiple_dropdowns_question" do