[mythtv] [PATCH] Regular expression changes
Dan Sheridan
djs52 at postman.org.uk
Thu Jul 22 03:36:10 EDT 2004
[Resending -- I see from the archives that my message was in somebody
else's thread and nobody seemed to notice it]
This patch changes the regular expressions which prepare data for
insertion into the recorded and oldrecorded tables. Previously, they
replaced " with \". If \" was part of the original string this results
in \\" which upsets mysql. It's probably a bug that there was a \" in
the string in the first place... but nevertheless I think this is a
nice defensive programming solution.
While I'm hacking: I'd like to add an i8n file for en_GB so that
"Movie search" becomes "Film search" with the appropriate change to
the SQL. Any pointers on how to go about this? How do I add the word
"movie" within the SQL to the translation file?
Dan.
-------------- next part --------------
From: Dan Sheridan <djs52 at postman.org.uk>
Subject: [PATCH] Defensive Regexps
To: Development of mythtv <mythtv-dev at mythtv.org>
Date: Thu Jul 8 07:05:31 2004 +0100
Myth failed to record a program last night (if anyone has a copy of
the first episode of the Long Firm...) because the description
included the string: \"
The regexp used to prepare the description for insertion into the
recorded and oldrecorded tables replaces " with \" resulting in \\"
which upsets mysql. It's probably a bug that there was a \" in the
string in the first place... but nevertheless I think this is a nice
defensive programming solution.
While I'm hacking: I'd like to add an i8n file for en_GB so that
"Movie search" becomes "Film search" with the appropriate change to
the SQL. Any pointers on how to go about this? How do I add the word
"movie" within the SQL to the translation file?
Dan.
Index: libs/libmythtv/programinfo.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/programinfo.cpp,v
retrieving revision 1.146
diff -u -d -r1.146 programinfo.cpp
--- libs/libmythtv/programinfo.cpp 6 Jul 2004 04:44:36 -0000 1.146
+++ libs/libmythtv/programinfo.cpp 8 Jul 2004 10:21:23 -0000
@@ -592,7 +592,7 @@
QString thequery;
QString sqltitle = title;
- sqltitle.replace(QRegExp("\""), QString("\\\""));
+ sqltitle.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
thequery = QString("SELECT count(*) FROM recorded WHERE title = \"%1\";")
.arg(sqltitle);
@@ -692,7 +692,7 @@
starts += "00";
QString myRecGroup = newrecgroup;
- myRecGroup.replace(QRegExp("'"), QString("\'"));
+ myRecGroup.replace(QRegExp("[^\\]'|^'"), QString("\'"));
QString querystr = QString("UPDATE recorded SET recgroup = '%1', "
"starttime = '%2' WHERE chanid = '%3' AND "
@@ -848,11 +848,11 @@
QString sqlcategory = category;
QString sqlrecgroup = recgroup;
- sqltitle.replace(QRegExp("\""), QString("\\\""));
- sqlsubtitle.replace(QRegExp("\""), QString("\\\""));
- sqldescription.replace(QRegExp("\""), QString("\\\""));
- sqlcategory.replace(QRegExp("\""), QString("\\\""));
- sqlrecgroup.replace(QRegExp("\""), QString("\\\""));
+ sqltitle.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqlsubtitle.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqldescription.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqlcategory.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqlrecgroup.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
QString query;
query = QString("INSERT INTO recorded (chanid,starttime,endtime,title,"
Index: libs/libmythtv/scheduledrecording.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/scheduledrecording.cpp,v
retrieving revision 1.101
diff -u -d -r1.101 scheduledrecording.cpp
--- libs/libmythtv/scheduledrecording.cpp 7 Jul 2004 22:38:52 -0000 1.101
+++ libs/libmythtv/scheduledrecording.cpp 8 Jul 2004 10:21:23 -0000
@@ -406,10 +406,10 @@
QString sqldescription = proginfo.description;
QString sqlcategory = proginfo.category;
- sqltitle.replace(QRegExp("\""), QString("\\\""));
- sqlsubtitle.replace(QRegExp("\""), QString("\\\""));
- sqldescription.replace(QRegExp("\""), QString("\\\""));
- sqlcategory.replace(QRegExp("\""), QString("\\\""));
+ sqltitle.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqlsubtitle.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqldescription.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
+ sqlcategory.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
QString query = QString("INSERT INTO oldrecorded (chanid,starttime,"
"endtime,title,subtitle,description,category,"
@@ -445,9 +445,9 @@
QString sqlsubtitle = proginfo.subtitle;
QString sqldescription = proginfo.description;
- sqltitle.replace(QRegExp("'"), QString("\\'"));
- sqlsubtitle.replace(QRegExp("'"), QString("\\'"));
- sqldescription.replace(QRegExp("'"), QString("\\'"));
+ sqltitle.replace(QRegExp("([^\\])'|^'"), QString("\\1\\'"));
+ sqlsubtitle.replace(QRegExp("([^\\])'|^'"), QString("\\1\\'"));
+ sqldescription.replace(QRegExp("([^\\])'|^'"), QString("\\1\\'"));
QString query = QString("DELETE FROM oldrecorded WHERE title = '%1' AND subtitle = '%2' AND description = '%3'")
.arg(sqltitle.utf8())
Index: libs/libmythtv/sr_items.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/sr_items.h,v
retrieving revision 1.6
diff -u -d -r1.6 sr_items.h
--- libs/libmythtv/sr_items.h 23 Jun 2004 20:32:54 -0000 1.6
+++ libs/libmythtv/sr_items.h 8 Jul 2004 10:21:23 -0000
@@ -21,7 +21,7 @@
virtual QString setClause(void)
{
QString value = getValue();
- value.replace(QRegExp("\""), QString("\\\""));
+ value.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
return QString("recordid = %1, %2 = \"%3\"")
.arg(parent.getRecordID())
@@ -51,7 +51,7 @@
virtual QString setClause(void) {
QString value = getValue();
- value.replace(QRegExp("\""), QString("\\\""));
+ value.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
return QString("recordid = %1, %2 = \"%3\"")
.arg(parent.getRecordID())
@@ -81,7 +81,7 @@
}
virtual QString setClause(void) {
QString value = getValue();
- value.replace(QRegExp("\""), QString("\\\""));
+ value.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
return QString("recordid = %1, %2 = \"%3\"")
.arg(parent.getRecordID())
@@ -110,7 +110,7 @@
virtual QString setClause(void) {
QString value = getValue();
- value.replace(QRegExp("\""), QString("\\\""));
+ value.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
return QString("recordid = %1, %2 = \"%3\"")
.arg(parent.getRecordID())
@@ -140,7 +140,7 @@
virtual QString setClause(void)
{
QString value = getValue();
- value.replace(QRegExp("\""), QString("\\\""));
+ value.replace(QRegExp("([^\\])\"|^\""), QString("\\1\\\""));
return QString("recordid = %1, %2 = \"%3\"")
.arg(parent.getRecordID())
--
Dan Sheridan -- Research Student -- LFCS, School of Informatics
University of Edinburgh, King's Buildings, Mayfield Road EH9 3JZ
-------------- next part --------------
--
Dan Sheridan -- Research Student -- LFCS, School of Informatics
University of Edinburgh, King's Buildings, Mayfield Road EH9 3JZ
More information about the mythtv-dev
mailing list