Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make StringVal stop at first NULL #36

Open
wants to merge 1 commit into
base: go1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions exif/regress_expected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var regressExpected = map[string]map[FieldName]string{
Make: `"Samsung Techwin"`,
DateTimeOriginal: `"2004:01:11 22:45:15"`,
DateTimeDigitized: `"2004:01:11 22:45:15"`,
ImageDescription: `"SAMSUNG DIGITAL CAMERA "`,
ImageDescription: `"SAMSUNG DIGITAL CAMERA "`,
ExifVersion: `"0220"`,
MeteringMode: `2`,
Flash: `1`,
Expand Down Expand Up @@ -1467,7 +1467,7 @@ var regressExpected = map[string]map[FieldName]string{
ThumbJPEGInterchangeFormatLength: `3385`,
ExifIFDPointer: `157`,
PixelXDimension: `1200`,
MakerNote: `""`,
MakerNote: `"\u0012)\t\u0008(b"`,
DateTimeDigitized: `"2011:01:24 22:06:02"`,
ResolutionUnit: `2`,
YCbCrPositioning: `1`,
Expand Down Expand Up @@ -2236,6 +2236,62 @@ var regressExpected = map[string]map[FieldName]string{
ISOSpeedRatings: `125`,
Contrast: `0`,
},
"gopro.jpg": map[FieldName]string{
ApertureValue: `"280/100"`,
ColorSpace: `1`,
ComponentsConfiguration: `""`,
CompressedBitsPerPixel: `"4334505/1382400"`,
Contrast: `0`,
CustomRendered: `0`,
DateTime: `"2012:04:29 12:32:31"`,
DateTimeDigitized: `"2012:04:29 12:32:31"`,
DateTimeOriginal: `"2012:04:29 12:32:31"`,
DeviceSettingDescription: `""`,
DigitalZoomRatio: `"1024/1024"`,
ExifIFDPointer: `146`,
ExifVersion: `"0221"`,
ExposureBiasValue: `"0/32"`,
ExposureIndex: `"0/0"`,
ExposureMode: `0`,
ExposureProgram: `2`,
ExposureTime: `"1/4418"`,
FNumber: `"280/100"`,
FileSource: `""`,
Flash: `32`,
FlashpixVersion: `"0100"`,
FocalLength: `"250/100"`,
FocalLengthIn35mmFilm: `16`,
GainControl: `0`,
ISOSpeedRatings: `100`,
ImageDescription: `"DCIM\\100GOPRO"`,
InteroperabilityIFDPointer: `632`,
InteroperabilityIndex: `"R98"`,
LightSource: `0`,
Make: `"GoPro"`,
MakerNote: `"@AMBA"`,
MaxApertureValue: `"280/100"`,
MeteringMode: `2`,
Model: `"HD2"`,
Orientation: `1`,
PixelXDimension: `3840`,
PixelYDimension: `2880`,
ResolutionUnit: `2`,
Saturation: `0`,
SceneCaptureType: `0`,
SceneType: `""`,
SensingMethod: `2`,
Sharpness: `0`,
ShutterSpeedValue: `"-12109/-1000"`,
Software: `"HD2.08.12.70"`,
SubjectDistance: `"0/0"`,
SubjectDistanceRange: `0`,
ThumbJPEGInterchangeFormat: `2036`,
ThumbJPEGInterchangeFormatLength: `9210`,
WhiteBalance: `0`,
XResolution: `"72/1"`,
YCbCrPositioning: `1`,
YResolution: `"72/1"`,
},
"has-lens-info.jpg": map[FieldName]string{
LensModel: `"iPhone 4S back camera 4.28mm f/2.4"`,
Model: `"iPhone 4S"`,
Expand Down
Binary file added exif/samples/gopro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions tiff/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tiff
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -180,7 +181,11 @@ func (t *Tag) convertVals() error {
switch t.Type {
case DTAscii:
if len(t.Val) > 0 {
t.strVal = string(t.Val[:len(t.Val)-1]) // ignore the last byte (NULL).
if index := bytes.IndexByte(t.Val, '\x00'); index != -1 {
t.strVal = string(t.Val[:index])
} else {
t.strVal = string(t.Val)
}
}
case DTByte:
var v uint8
Expand Down Expand Up @@ -390,7 +395,13 @@ func (t *Tag) String() string {

func (t *Tag) MarshalJSON() ([]byte, error) {
switch t.format {
case StringVal, UndefVal:
case StringVal:
if s, err := t.StringVal(); err != nil {
return []byte(`null`), err
} else {
return json.Marshal(s)
}
case UndefVal:
return nullString(t.Val), nil
case OtherVal:
return []byte(fmt.Sprintf("unknown tag type '%v'", t.Type)), nil
Expand Down