Added couple of checks for invalid or empty chapter language entries.

This commit is contained in:
Moritz Bunkus 2005-01-30 19:19:03 +00:00
parent c10d088868
commit c687069807
3 changed files with 58 additions and 13 deletions

View File

@ -1,5 +1,9 @@
2005-01-30 Moritz Bunkus <moritz@bunkus.org> 2005-01-30 Moritz Bunkus <moritz@bunkus.org>
* mmg: bug fix: It was possible to create chapter entries with
invalid or even empty language entries. Not only are those
invalid, such XML files can also not be loaded by mmg.
* mmg: bug fix: Overwriting a chapter file did not erase the * mmg: bug fix: Overwriting a chapter file did not erase the
previous file. So if the previous file was bigger than the current previous file. So if the previous file was bigger than the current
chapters then garbage remained at the end of the file. chapters then garbage remained at the end of the file.

View File

@ -1904,12 +1904,16 @@ mmg_app::OnInit() {
cfg->SetPath(wxT("/chapter_editor")); cfg->SetPath(wxT("/chapter_editor"));
if (cfg->Read(wxT("default_language"), &k)) { if (cfg->Read(wxT("default_language"), &k)) {
if (k.length() == 0) if (k.length() == 0)
k = wxT("eng"); k = wxT("und");
default_chapter_language = to_utf8(k).c_str(); default_chapter_language = to_utf8(k).c_str();
if (!is_valid_iso639_2_code(default_chapter_language.c_str()))
default_chapter_language = "und";
} else } else
default_chapter_language = "eng"; default_chapter_language = "und";
if (cfg->Read(wxT("default_country"), &k)) if (cfg->Read(wxT("default_country"), &k) && (0 < k.length()))
default_chapter_country = to_utf8(k).c_str(); default_chapter_country = to_utf8(k).c_str();
if (!is_valid_iso639_1_code(default_chapter_country.c_str()))
default_chapter_country = "";
app = this; app = this;
mdlg = new mmg_dialog(); mdlg = new mmg_dialog();

View File

@ -121,7 +121,9 @@ chapter_values_dlg::chapter_values_dlg(wxWindow *parent,
siz_input->Add(new wxStaticText(this, wxID_STATIC, wxT("Language:")), siz_input->Add(new wxStaticText(this, wxID_STATIC, wxT("Language:")),
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10); 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
cob_language = new wxComboBox(this, wxID_STATIC, wxT("")); cob_language = new wxComboBox(this, wxID_STATIC, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
siz_input->Add(cob_language, 0, wxGROW, 0); siz_input->Add(cob_language, 0, wxGROW, 0);
siz_input->Add(0, 1, 1, wxGROW, 0); siz_input->Add(0, 1, 1, wxGROW, 0);
@ -130,7 +132,9 @@ chapter_values_dlg::chapter_values_dlg(wxWindow *parent,
siz_input->Add(new wxStaticText(this, wxID_STATIC, wxT("Country:")), siz_input->Add(new wxStaticText(this, wxID_STATIC, wxT("Country:")),
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10); 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
cob_country = new wxComboBox(this, wxID_STATIC, wxT("")); cob_country = new wxComboBox(this, wxID_STATIC, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
siz_input->Add(cob_country, 0, wxGROW, 0); siz_input->Add(cob_country, 0, wxGROW, 0);
} else { } else {
@ -153,7 +157,9 @@ chapter_values_dlg::chapter_values_dlg(wxWindow *parent,
new wxCheckBox(this, ID_CVD_CB_LANGUAGE, wxT("Set language to:")); new wxCheckBox(this, ID_CVD_CB_LANGUAGE, wxT("Set language to:"));
cb_language->SetValue(false); cb_language->SetValue(false);
siz_input->Add(cb_language, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10); siz_input->Add(cb_language, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
cob_language = new wxComboBox(this, wxID_STATIC, wxT("")); cob_language = new wxComboBox(this, wxID_STATIC, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
cob_language->Enable(false); cob_language->Enable(false);
siz_input->Add(cob_language, 0, wxGROW, 0); siz_input->Add(cob_language, 0, wxGROW, 0);
@ -165,7 +171,9 @@ chapter_values_dlg::chapter_values_dlg(wxWindow *parent,
new wxCheckBox(this, ID_CVD_CB_COUNTRY, wxT("Set country to:")); new wxCheckBox(this, ID_CVD_CB_COUNTRY, wxT("Set country to:"));
cb_country->SetValue(false); cb_country->SetValue(false);
siz_input->Add(cb_country, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10); siz_input->Add(cb_country, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
cob_country = new wxComboBox(this, wxID_STATIC, wxT("")); cob_country = new wxComboBox(this, wxID_STATIC, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
cob_country->Enable(false); cob_country->Enable(false);
siz_input->Add(cob_country, 0, wxGROW, 0); siz_input->Add(cob_country, 0, wxGROW, 0);
@ -173,7 +181,6 @@ chapter_values_dlg::chapter_values_dlg(wxWindow *parent,
siz_all->Add(siz_input, 3, wxGROW | wxLEFT | wxRIGHT, 25); siz_all->Add(siz_input, 3, wxGROW | wxLEFT | wxRIGHT, 25);
cob_language->Append(wxT(""));
for (i = 0; i < sorted_iso_codes.Count(); i++) { for (i = 0; i < sorted_iso_codes.Count(); i++) {
cob_language->Append(sorted_iso_codes[i]); cob_language->Append(sorted_iso_codes[i]);
if (extract_language_code(sorted_iso_codes[i]) == old_def_language) if (extract_language_code(sorted_iso_codes[i]) == old_def_language)
@ -380,7 +387,9 @@ tab_chapters::tab_chapters(wxWindow *parent,
siz_fg->Add(st_language, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10); siz_fg->Add(st_language, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
cob_language_code = cob_language_code =
new wxComboBox(this, ID_CB_CHAPTERSELECTLANGUAGECODE, wxT("")); new wxComboBox(this, ID_CB_CHAPTERSELECTLANGUAGECODE, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
for (i = 0; i < sorted_iso_codes.Count(); i++) for (i = 0; i < sorted_iso_codes.Count(); i++)
cob_language_code->Append(sorted_iso_codes[i]); cob_language_code->Append(sorted_iso_codes[i]);
cob_language_code->SetValue(wxT("")); cob_language_code->SetValue(wxT(""));
@ -391,7 +400,9 @@ tab_chapters::tab_chapters(wxWindow *parent,
st_country = new wxStaticText(this, wxID_STATIC, wxT("Country:")); st_country = new wxStaticText(this, wxID_STATIC, wxT("Country:"));
siz_line->Add(st_country, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); siz_line->Add(st_country, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
cob_country_code = cob_country_code =
new wxComboBox(this, ID_CB_CHAPTERSELECTCOUNTRYCODE, wxT("")); new wxComboBox(this, ID_CB_CHAPTERSELECTCOUNTRYCODE, wxT(""),
wxDefaultPosition, wxDefaultSize, 0, NULL,
wxCB_DROPDOWN | wxCB_READONLY);
cob_country_code->Append(wxT("")); cob_country_code->Append(wxT(""));
for (i = 0; cctlds[i] != NULL; i++) for (i = 0; cctlds[i] != NULL; i++)
cob_country_code->Append(wxU(cctlds[i])); cob_country_code->Append(wxU(cctlds[i]));
@ -822,6 +833,7 @@ tab_chapters::verify_atom_recursively(EbmlElement *e) {
KaxChapterLanguage *language; KaxChapterLanguage *language;
KaxChapterString *cs; KaxChapterString *cs;
wxString label; wxString label;
string lang;
uint32_t i; uint32_t i;
if (dynamic_cast<KaxEditionUID *>(e) != NULL) if (dynamic_cast<KaxEditionUID *>(e) != NULL)
@ -867,6 +879,16 @@ tab_chapters::verify_atom_recursively(EbmlElement *e) {
wxICON_ERROR); wxICON_ERROR);
return false; return false;
} }
lang = string(*language);
if ((0 == lang.size()) || !is_valid_iso639_2_code(lang.c_str())) {
wxMessageBox(wxT("The selected language '") + wxU(lang.c_str()) +
wxT("' for the chapter '") + label +
wxT("' is not a valid language code. Please select one of "
"the predefined ones."),
wxT("Chapter verification error"), wxCENTER | wxOK |
wxICON_ERROR);
return false;
}
for (i = 0; i < chapter->ListSize(); i++) for (i = 0; i < chapter->ListSize(); i++)
if (dynamic_cast<KaxChapterAtom *>((*chapter)[i]) != NULL) if (dynamic_cast<KaxChapterAtom *>((*chapter)[i]) != NULL)
@ -1320,15 +1342,23 @@ tab_chapters::on_chapter_name_changed(wxCommandEvent &evt) {
void void
tab_chapters::on_set_default_values(wxCommandEvent &evt) { tab_chapters::on_set_default_values(wxCommandEvent &evt) {
vector<string> parts; wxString language;
chapter_values_dlg dlg(this, true, wxU(default_chapter_language.c_str()), chapter_values_dlg dlg(this, true, wxU(default_chapter_language.c_str()),
wxU(default_chapter_country.c_str())); wxU(default_chapter_country.c_str()));
if (dlg.ShowModal() != wxID_OK) if (dlg.ShowModal() != wxID_OK)
return; return;
default_chapter_language = language = extract_language_code(dlg.cob_language->GetValue());
wxMB(extract_language_code(dlg.cob_language->GetValue())); if (!is_valid_iso639_2_code(to_utf8(language.c_str()).c_str())) {
wxMessageBox(wxT("The language '") + language +
wxT("' is not a valid language and cannot be selected."),
wxT("Invalid language selected"),
wxICON_ERROR | wxOK);
return;
}
default_chapter_language = wxMB(language);
default_chapter_country = wxMB(dlg.cob_country->GetValue()); default_chapter_country = wxMB(dlg.cob_country->GetValue());
} }
@ -1405,6 +1435,13 @@ tab_chapters::on_set_values(wxCommandEvent &evt) {
if (dlg.cb_language->IsChecked()) { if (dlg.cb_language->IsChecked()) {
s = extract_language_code(dlg.cob_language->GetValue()); s = extract_language_code(dlg.cob_language->GetValue());
if (!is_valid_iso639_2_code(to_utf8(s.c_str()).c_str())) {
wxMessageBox(wxT("The language '") + s +
wxT("' is not a valid language and cannot be selected."),
wxT("Invalid language selected"),
wxICON_ERROR | wxOK);
return;
}
set_values_recursively(id, s, true); set_values_recursively(id, s, true);
} }
if (dlg.cb_country->IsChecked()) { if (dlg.cb_country->IsChecked()) {