jirentabu / crashrpt

Automatically exported from code.google.com/p/crashrpt
0 stars 0 forks source link

std::string CCrashHandler::XmlEncodeStr(CString sText) error #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
***NOTE*** Please do create a NEW issue per each detected bug! Do not list
all detected problems in single issue record!

What steps will reproduce the problem?
1.run D:\Test\ChineseDir+EnglishDir\CrashRptTest.exe
2.the throw exception 
3.the sender dialog display blank

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

std::string CCrashHandler::XmlEncodeStr(CString sText)
encoding the text ascii use "return std::string(strconv.t2a(sResult));"

but read the file use 
"int CCrashInfoReader::Init(CString sCrashInfoFileName)
strconv.utf82t(szAppName);
"

simple modify below

///////////
std::string& replaceInPlace(std::string& str, const std::string& from, const 
std::string& to, std::string::size_type start = 0)
{   
    std::string result;
    std::string::size_type pos = 0;
    result.append(str, 0, start);
    do
    {
        pos = str.find(from, start);
        if (pos != std::string::npos)
        {
            result.append(str, start, pos - start);
            result.append(to);
            start = pos + from.length();
        }
        else result.append(str, start, str.size() - start);
    }
    while (pos != std::string::npos);
    str.swap(result);
    return str;
}
// Helper method that encodes string into UTF-8 and replaces some characters
std::string CCrashHandler::XmlEncodeStr(CString sText)
{  
  strconv_t strconv;

  // Convert to UTF-8 encoding

  LPCSTR pszEncodedStr = strconv.t2utf8(sText);

  // Replace characters restricted by XML
//  CString sResult = pszEncodedStr;
//  sResult.Replace(_T("&"), _T("&amp"));
//  sResult.Replace(_T("\""), _T("&quot"));
//  sResult.Replace(_T("'"), _T("&apos"));  
//  sResult.Replace(_T("<"), _T("&lt"));
//sResult.Replace(_T(">"), _T("&gt"));
  // Replace 
  std::string str(pszEncodedStr);
  replaceInPlace(str, std::string("&"), std::string("&amp"));
  replaceInPlace(str, std::string("\""), std::string("&quot"));
  replaceInPlace(str, std::string("'"), std::string("&apos"));
  replaceInPlace(str, std::string("<"), std::string("&lt"));
  replaceInPlace(str, std::string(">"), std::string("&gt"));

  return std::string(pszEncodedStr);

  //return std::string(strconv.t2a(sResult));
}
////////////////////////////////////////////

thanks

Original issue reported on code.google.com by liling...@gmail.com on 22 Oct 2010 at 6:44

GoogleCodeExporter commented 9 years ago

Original comment by zexspect...@gmail.com on 22 Oct 2010 at 2:51

GoogleCodeExporter commented 9 years ago
Please provide more information:

1. What version of CrashRpt did you use? 

2. I do not see a mistake in the XmlEncodeStr code. 

std::string CCrashHandler::XmlEncodeStr(CString sText)
encoding the text ascii use "return std::string(strconv.t2a(sResult));"

Since the sResult string was already UTF-8-encoded and stored as ASCII, there 
is nothing bad in expanding it to wide char, then replacing the restricted 
characters and converting to ASCII. Am I wrong?

3. Are you sure your replaceInPlace function really "replaces in place"? I see 
that it creates another string named "result" and copies the source string to 
it, then swaps result and source. Is this called "in-place"?

4. Why do you return std::string(pszEncodedStr)?
isn't it correct to return std::string(str);

Original comment by zexspect...@gmail.com on 30 Oct 2010 at 7:03

GoogleCodeExporter commented 9 years ago
1.when I used Ver.1.2.3 , it'ok, updated to ver.1.2.7 , i got the error!
2."the sResult string was already UTF-8-encoded" but "expanding it to wide 
char" is error, CString is wrong.
3.i just get "replaceInPlace" from "Poco"( refrence http://pocoproject.org/) 
for replace CString
4.oh , i was wrong, your are wright

Original comment by liling...@gmail.com on 1 Nov 2010 at 1:38

GoogleCodeExporter commented 9 years ago
Fixed in v.1.2.8

Original comment by zexspect...@gmail.com on 15 Feb 2011 at 3:43