commit 2622c99dd5ab337d67e84da6e5dedef1d6482034
Author: Stephan Witt <[email protected]>
Date:   Sat Mar 28 11:07:56 2015 +0100

    #9477 improved argument handling for LFUN_SPELLING_ADD,LFUN_SPELLING_IGNORE 
and LFUN_SPELLING_REMOVE (backport)

diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 151f955..7d84cdc 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1016,6 +1016,7 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_SPELLING_ADD
  * \li Action: Add the word under the cursor to the respective
  *             spell checker dictionary.
+ *             The default for the language is retrieved from the cursor 
position.
  * \li Syntax: spelling-add [<STRING>] [<LANG>]
  * \li Params: <WORD>: word to add
                <LANG>: language name (see file languages)
@@ -1027,6 +1028,7 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_SPELLING_IGNORE
  * \li Action: Let the spell checker ignore the word under the cursor
  *             in the current session for the given language.
+ *             The default for the language is retrieved from the cursor 
position.
  * \li Syntax: spelling-ignore [<WORD>] [<LANG>]
  * \li Params: <WORD>: word to ignore
                <LANG>: language name (see file languages)
@@ -1038,9 +1040,10 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_SPELLING_REMOVE
  * \li Action: Remove the word under the cursor from the respective
  *             spell checker dictionary.
+ *             The default for the language is retrieved from the cursor 
position.
  * \li Syntax: spelling-remove [<STRING>] [<LANG>]
  * \li Params: <WORD>: word to remove
-               <LANG>: language name (see file languages)
+ *             <LANG>: language name (see file languages)
  * \li Origin: SWitt, 28 July 2010
  * \endvar
  */
diff --git a/src/Text3.cpp b/src/Text3.cpp
index ae4559b..294fc05 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -2241,8 +2241,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                word = cur.selectionAsString(false);
                        }
                        lang = const_cast<Language *>(cur.getFont().language());
-               } else
+               } else if (cmd.getArg(1).empty()) {
+                       // optional language argument is missing
+                       // use the language at cursor position
+                       lang = const_cast<Language *>(cur.getFont().language());
+               } else {
                        lang = const_cast<Language 
*>(languages.getLanguage(cmd.getArg(1)));
+               }
                WordLangTuple wl(word, lang);
                theSpellChecker()->insert(wl);
                break;
@@ -2260,8 +2265,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                word = cur.selectionAsString(false);
                        }
                        lang = const_cast<Language *>(cur.getFont().language());
-               } else
+               } else if (cmd.getArg(1).empty()) {
+                       lang = const_cast<Language *>(cur.getFont().language());
+               } else {
                        lang = const_cast<Language 
*>(languages.getLanguage(cmd.getArg(1)));
+               }
                WordLangTuple wl(word, lang);
                theSpellChecker()->accept(wl);
                break;
@@ -2279,8 +2287,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                word = cur.selectionAsString(false);
                        }
                        lang = const_cast<Language *>(cur.getFont().language());
-               } else
+               } else if (cmd.getArg(1).empty()) {
+                       lang = const_cast<Language *>(cur.getFont().language());
+               } else {
                        lang = const_cast<Language 
*>(languages.getLanguage(cmd.getArg(1)));
+               }
                WordLangTuple wl(word, lang);
                theSpellChecker()->remove(wl);
                break;
@@ -2933,7 +2944,12 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & 
cmd,
        case LFUN_SPELLING_ADD:
        case LFUN_SPELLING_IGNORE:
        case LFUN_SPELLING_REMOVE:
-               enable = theSpellChecker();
+               enable = theSpellChecker() != NULL;
+               if (enable && !cmd.getArg(1).empty()) {
+                       // validate explicitly given language
+                       Language const * const lang = const_cast<Language 
*>(languages.getLanguage(cmd.getArg(1)));
+                       enable &= lang != NULL;
+               }
                break;
 
        case LFUN_LAYOUT: {
diff --git a/status.21x b/status.21x
index 3edce39..59c6491 100644
--- a/status.21x
+++ b/status.21x
@@ -139,6 +139,12 @@ What's new
 
 - Fix consecutive merging of tabular cells.
 
+- Fix crash with missing optional or wrong arguments for
+  * LFUN_SPELLING_ADD,
+  * LFUN_SPELLING_IGNORE and
+  * LFUN_SPELLING_REMOVE
+  (bug 9477).
+
 
 * INTERNALS
 

Reply via email to