Changeset 31951

Show
Ignore:
Timestamp:
07.09.2017 17:57:31 (2 weeks ago)
Author:
ak19
Message:

Bugfix to depositor: commas in metadata entered through the depositor were not being preserved, as commas were used to split the many fields (of form cgi params) on in depositoraction.cpp. Now depositor.dm escapes the commas with URL encoding in the metadatafields section of the depositor step1 form, while depositoraction.cpp decodes the URL-encoded commas again.

Location:
main/trunk/greenstone2
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/macros/deposit.dm

    r29403 r31951  
    194194        \} 
    195195         
    196         var inputObj;  
     196        var inputObj; 
    197197        if (metadataField.type=="text") \{ 
    198198            inputObj = document.createElement("input"); 
     
    221221 
    222222function check\_submit (gotopage) \{ 
     223 
     224  // escape any commas in the metadata fields in order to preserve them 
     225  // preserve any commas in the metadata fields by escaping them here 
     226  // so that meta values containing commas don't end up split at comma by depositoraction.cpp 
     227 
     228  // Get just the part of form containing metadata input elements 
     229  // as we don't want to modify any other part of the form 
     230  var formContainer = document.getElementById('formcontainer');  
     231  // https://stackoverflow.com/questions/25302684/getting-all-child-input-elements-within-a-div 
     232  var inputNodes = formContainer.getElementsByTagName('input'); 
     233  for(var i = 0; i < inputNodes.length; i++) \{ 
     234    var inputNode = inputNodes[i]; 
     235    if(inputNode.type == 'text') \{ 
     236      if(inputNode.value) \{ 
     237        var val = inputNode.value; 
     238    // To replace all occurrences in a string, and not just the 1st, need to do a global 
     239    // substitution. See https://www.w3schools.com/jsref/jsref_replace.asp 
     240        inputNode.value = val.replace(/,/g, "%2C"); 
     241      \} 
     242    \} 
     243  \} 
     244 
     245  // Proceed as usual from here on to submit the modified form 
     246 
    223247  var form = document.depositorform; 
    224248  form.p.value = gotopage; 
  • main/trunk/greenstone2/runtime-src/src/recpt/depositoraction.cpp

    r31687 r31951  
    833833            cerr << "args val = "<<args_val<<endl; 
    834834            decode_cgi_arg(args_val); 
    835             cerr << "decoded" << args_val<<endl; 
     835            cerr << "decoded = " << args_val<<endl; 
    836836            text_t args_suffix = substr(args_name.begin()+prefix_len+3,args_name.end());  
    837837 
     
    846846                metadata_file += args_suffix; 
    847847                metadata_file += "\">"; 
    848                 metadata_file += xml_safe(mdvalues[i]); 
     848                // originally literal commas entered for metadata like dc.Subject 
     849                // come in (extra) URL encoded, as %2C at this point in the code 
     850                // Decode any commas now before writing them into metadata.xml 
     851                metadata_file += xml_safe(decode_commas(mdvalues[i])); 
    849852                metadata_file += "</Metadata>\n"; 
    850853