In the standard book class, if there are very long section titles, \tableofcontents tries to produce justified text.
How can I produce a table of contents so that the section titles are typeset flush left, ragged right?
That is, I would like to produce something like this (note that the page numbers should be aligned):
1.2.2 Short title . . . . . 42
1.2.3 Long section title
can be wrapped . . . . 44
1.2.4 Another short title . 45
(The default output is almost identical, except that Latex uses hyphenation and variable inter-word spacing to make sure that the right margins are aligned for all multi-line section titles.)
I assumed that I could easily use the titletoc package—just re-define the toc entries and add \raggedright somewhere. However, none of my attempts were successful.

tocstylewithtitletocplus your patch in my example, it seems that subsection entries are set ragged right, but section entries aren't. – lockstep Feb 20 '12 at 17:31titletoc. But loading it with no special setting gives the same result. – egreg Feb 20 '12 at 17:38bookclass. Upvoted. – lockstep Feb 20 '12 at 17:43tocstyleversion—in particular, this version does not try to squeeze too much text on one line. In thetocstylesolution, the right margin of the section titles seemed to be a bit too close to the page numbers in some cases. – Jukka Suomela Feb 20 '12 at 17:52