Commit 98383f80 authored by Clinton Stimpson's avatar Clinton Stimpson

Unicode: check encoding of files given to configure_file.

UTF-16 and UTF-32 files are rejected.
parent e21ffaf8
......@@ -3518,6 +3518,20 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
return 0;
}
cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
if(bom != cmsys::FStream::BOM_None &&
bom != cmsys::FStream::BOM_UTF8)
{
cmOStringStream e;
e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
<< sinfile;
this->IssueMessage(cmake::FATAL_ERROR, e.str());
return 0;
}
// rewind to copy BOM to output file
fin.seekg(0);
// now copy input to output and expand variables in the
// input file at the same time
std::string inLine;
......
......@@ -95,6 +95,7 @@ add_RunCMake_test(TargetPolicies)
add_RunCMake_test(alias_targets)
add_RunCMake_test(interface_library)
add_RunCMake_test(no_install_prefix)
add_RunCMake_test(configure_file)
find_package(Qt4 QUIET)
find_package(Qt5Core QUIET)
......
cmake_minimum_required(VERSION 3.0)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt)
include(RunCMake)
run_cmake(NO-BOM)
run_cmake(UTF8-BOM)
run_cmake(UTF16LE-BOM)
run_cmake(UTF16BE-BOM)
run_cmake(UTF32LE-BOM)
run_cmake(UTF32BE-BOM)
CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt)
CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt)
CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt)
CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt)
configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt)
......@@ -329,6 +329,7 @@ fi
KWSYS_CXX_SOURCES="\
Directory \
EncodingCXX \
FStream \
Glob \
RegularExpression \
SystemTools"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment