I wanted to style chapter headings, found out about titlesec and wrote the document like this:

\documentclass[a4paper,12pt]{book}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[serbianc]{babel}

\usepackage{titlesec}
\usepackage{xcolor}

\definecolor{crvena}{rgb}{.647,.129,.149}
\definecolor{plava}{rgb}{.204,.353,.541}

\titleformat
{\chapter} % command
[display] % shape
{\bfseries\flushright\Huge\color{crvena}} % format
{\ \thechapter} % label
{0.5ex} % sep
{
\vspace{1ex}
} % before-code
[
\vspace{-0.5ex}%
\color{plava}\rule{\textwidth}{2.3pt}
] % after-code

\begin{document}
\tableofcontents
\chapter{Лавиринт}


After that I wrote some text and finished with:

\end{document}


The result is fine, as can be seen from the image:

ToC:

What has caused 1 [Pleaseinsertintopreamble] to be written instead of 1 Лавиринт and how to fix it?

EDIT 1: I tried to use fancyhdr, but got this:

ToC is fine:

• Welcome to TeX.SX! The problem usually is associated to the utf8x option to inputenc rather than utf8. – egreg Mar 8 '14 at 20:09
• Thanks. :) I've seen that the problem occurs with utf8x, so I was somewhat surprised to see it happen with utf8 as well. If I add \usepackage{fancyhdr}, ToC works fine, but then headers are wrong. I'm new to both fancyhdr and titlesec, so I have no clue what's going on. : ) – Milos Mar 8 '14 at 20:17

The serbianc module for babel seems to enforce using the utf8x option for inputenc and the package ucs which is, in my opinion, wrong.
A workaround seems to be specifying utf8x prior to utf8.
\documentclass[a4paper,12pt]{book}

However, I would ask the maintainer of babel to remove the setting, leaving the user the choice of what option for inputenc to use. And I'd much prefer utf8.