0001-Implements-sanitation-of-entries-names.patch

Olivier Dalang, 2013-03-16 01:05 PM

Download (2.43 KB)

View differences:

src/core/qgsproject.cpp
63 63
  // be sure to include the canonical root node
64 64
  keyTokens.push_front( "properties" );
65 65

  
66
  return keyTokens;
66
  //sanitize keys since an unvalid xml name will make the project file unreadable !
67
  QStringList sanitizedKeyTokens = QStringList();
68
  for (int i = 0; i < keyTokens.size(); ++i){
69
    QString sanitizedKey = keyTokens.at(i);
70

  
71
    //replace invalid chars
72
    //TODO : this is too exclusive, this should be the regexp, but I don't manage to make it work : http://www.w3.org/TR/REC-xml/#NT-NameChar
73
    //QString nameCharRegexp = QString( "[^:_A-Z_a-z0-9\\xC0-\\xD6\\xC0-\\xD6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD\\x10000-\\xEFFFF\\-\\.0-9\\xB7\\x0300-\\x036F\\x203F-\\x2040]" );
74
    QString nameCharRegexp = QString( "[^:_A-Za-z0-9]" );
75
    sanitizedKey = sanitizedKey.replace( QRegExp(nameCharRegexp) , "_" );
76

  
77
    //prepend "_" if startchar is invalid
78
    //TODO : this is too exclusive, this should be the regexp, but I don't manage to make it work : http://www.w3.org/TR/REC-xml/#NT-NameStartChar
79
    //QString nameStartCharRegexp = QString( "^[^:_A-Z_a-z0-9\\xC0-\\xD6\\xC0-\\xD6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD\\x10000-\\xEFFFF]" );
80
    QString nameStartCharRegexp = QString( "^[^:_A-Za-z]" );
81
    if( sanitizedKey.contains( QRegExp(nameStartCharRegexp) ) ){
82
      sanitizedKey = '_' + sanitizedKey;
83
    }
84

  
85
    sanitizedKeyTokens.append(sanitizedKey);
86
  }
87

  
88
  return sanitizedKeyTokens;
67 89
} // makeKeyTokens_
68 90

  
69 91

  
70
-